Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import { readdirSync, readFileSync } from 'node:fs'; |
| 2 | import { describe, expect, it } from 'vitest'; |
| 3 | import { |
| 4 | appendManagedBlocks, |
| 5 | pathBlockForShell, |
| 6 | reconcileManagedPathBlock, |
| 7 | type Shell, |
| 8 | } from 'src/services/shell-config'; |
| 9 | |
| 10 | /** |
| 11 | * Managed PATH block contract conformance. |
| 12 | * |
| 13 | * The fixtures under test/managed-block-fixtures also drive install.sh's |
| 14 | * write_path_block through the shell harness |
| 15 | * (test/install-sh-release-resolution.test.sh), so an edit to either |
| 16 | * implementation fails one of the two suites until the other side produces |
| 17 | * byte-identical output again. Each fixture directory holds the rc file |
| 18 | * `before` the run, the raw `bin-dir` (with `__HOME__` standing in for the |
| 19 | * home directory), the target `shell`, and the expected `after` bytes. |
| 20 | */ |
| 21 | |
| 22 | const FIXTURES_URL = new URL('../../../../../test/managed-block-fixtures/', import.meta.url); |
| 23 | const HOME = '/home/conformance'; |
| 24 | |
| 25 | const readFixture = (caseName: string, file: string): string => |
| 26 | readFileSync(new URL(`${caseName}/${file}`, FIXTURES_URL), 'utf8'); |
| 27 | |
| 28 | const fixtureNames = readdirSync(FIXTURES_URL, { withFileTypes: true }) |
| 29 | .filter(entry => entry.isDirectory()) |
| 30 | .map(entry => entry.name) |
| 31 | .sort(); |
| 32 | |
| 33 | describe('managed PATH block conformance with install.sh', () => { |
| 34 | it('finds the shared fixtures', () => { |
| 35 | expect(fixtureNames.length).toBeGreaterThan(0); |
| 36 | }); |
| 37 | |
| 38 | it.each(fixtureNames)('reconciles %s byte-identically to install.sh', caseName => { |
| 39 | const binDir = readFixture(caseName, 'bin-dir').trim().replace('__HOME__', HOME); |
| 40 | const shell = readFixture(caseName, 'shell').trim() as Shell; |
| 41 | const before = readFixture(caseName, 'before'); |
| 42 | const expected = readFixture(caseName, 'after'); |
| 43 | |
| 44 | // Mirror installShellIntegration's write flow: a current block leaves the |
| 45 | // file untouched, a stale block is reconciled, and an absent block is |
| 46 | // appended after the existing content. |
| 47 | const pathBlock = pathBlockForShell(shell, binDir, HOME); |
| 48 | const reconciliation = reconcileManagedPathBlock(before, pathBlock); |
| 49 | const after = |
| 50 | reconciliation.state === 'current' |
| 51 | ? before |
| 52 | : reconciliation.state === 'stale' |
| 53 | ? reconciliation.reconciled |
| 54 | : appendManagedBlocks(before, [pathBlock]); |
| 55 | |
| 56 | expect(after).toBe(expected); |
| 57 | }); |
| 58 | }); |