Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | /** |
| 2 | * The seeded world, without a container: every rig starts from the same |
| 3 | * state, and that state is pinned, so a change to the seed is a decision and |
| 4 | * not a drift. `pass^k` compares attempts of one journey; it means nothing if |
| 5 | * they did not start alike. |
| 6 | */ |
| 7 | |
| 8 | import { describe, expect, it } from 'bun:test'; |
| 9 | import { |
| 10 | CONSUMER_PROJECT, |
| 11 | CONSUMER_USER_ID, |
| 12 | DEVELOPER_PROJECT, |
| 13 | World, |
| 14 | worldHash, |
| 15 | type Connection, |
| 16 | } from '@e2e-tests/cli-fake-backend'; |
| 17 | |
| 18 | /** |
| 19 | * `worldHash(new World())`. Update it in the change that alters the seed, and |
| 20 | * say in that change why: every earlier eval batch was run against the old one. |
| 21 | */ |
| 22 | const SEEDED_WORLD_HASH = '7621fa4ed357c514'; |
| 23 | |
| 24 | describe('the seeded world', () => { |
| 25 | it('hashes the same in every new instance', () => { |
| 26 | expect(worldHash(new World())).toBe(worldHash(new World())); |
| 27 | }); |
| 28 | |
| 29 | it('is the pinned seed', () => { |
| 30 | expect(worldHash(new World())).toBe(SEEDED_WORLD_HASH); |
| 31 | }); |
| 32 | |
| 33 | it('ignores the deployment’s user API key, which no request changes', () => { |
| 34 | // A digest of a credential is a password hash to any reader, and the key is |
| 35 | // fixed per rig, so it is not state two runs are compared by. |
| 36 | expect(worldHash(new World({ userApiKey: 'uk_e2e_another_deployment' }))).toBe( |
| 37 | worldHash(new World()) |
| 38 | ); |
| 39 | }); |
| 40 | }); |
| 41 | |
| 42 | describe('worldHash', () => { |
| 43 | it('does not depend on the order of an object’s keys', () => { |
| 44 | const world = new World(); |
| 45 | world.connect(CONSUMER_PROJECT.label, CONSUMER_USER_ID, 'slack'); |
| 46 | const before = worldHash(world); |
| 47 | const [connection] = world.connections; |
| 48 | world.connections[0] = Object.fromEntries(Object.entries(connection!).reverse()) as Connection; |
| 49 | expect(worldHash(world)).toBe(before); |
| 50 | }); |
| 51 | |
| 52 | // One change per kind of state a request can leave behind. |
| 53 | const changes: ReadonlyArray<[string, (world: World) => void]> = [ |
| 54 | [ |
| 55 | 'a connection', |
| 56 | world => void world.connect(CONSUMER_PROJECT.label, CONSUMER_USER_ID, 'slack'), |
| 57 | ], |
| 58 | ['an auth config', world => void world.authConfigForToolkit(CONSUMER_PROJECT.label, 'slack')], |
| 59 | ['a login session', world => void world.createLoginSession()], |
| 60 | [ |
| 61 | 'a tool-router session', |
| 62 | world => void world.createToolRouterSession(DEVELOPER_PROJECT.label, CONSUMER_USER_ID), |
| 63 | ], |
| 64 | ['a minted project key', world => void world.mintProjectKey(DEVELOPER_PROJECT.label, 'e2e')], |
| 65 | [ |
| 66 | 'a release', |
| 67 | world => void world.releases.push({ tag: 'v0.0.1', prerelease: false, assets: [] }), |
| 68 | ], |
| 69 | ['how links complete', world => void (world.linkCompletesAfterPolls = null)], |
| 70 | ['a tool execution', world => void world.nextLogId()], |
| 71 | ]; |
| 72 | |
| 73 | for (const [name, change] of changes) { |
| 74 | it(`changes with ${name}`, () => { |
| 75 | const world = new World(); |
| 76 | change(world); |
| 77 | expect(worldHash(world)).not.toBe(worldHash(new World())); |
| 78 | }); |
| 79 | } |
| 80 | |
| 81 | it('changes when a connection’s status does', () => { |
| 82 | const world = new World(); |
| 83 | const pending = world.beginConnection({ |
| 84 | projectLabel: CONSUMER_PROJECT.label, |
| 85 | userId: CONSUMER_USER_ID, |
| 86 | toolkit: 'slack', |
| 87 | }); |
| 88 | const before = worldHash(world); |
| 89 | world.authorizeConnection(pending.id); |
| 90 | expect(worldHash(world)).not.toBe(before); |
| 91 | }); |
| 92 | }); |