|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import fs from 'node:fs'; |
| 3 | +import path from 'node:path'; |
| 4 | +import { test } from 'vitest'; |
| 5 | +import { mkdtempForTestSync } from './tmp-dir.fixtures.ts'; |
| 6 | +import { isSourceCheckoutProjectRoot, resolveAgentDeviceProjectRoot } from './project-root.ts'; |
| 7 | + |
| 8 | +/** |
| 9 | + * The shape that separates a tree whose code can be rebuilt under its own version |
| 10 | + * from an installed copy of a published one (`daemon-launch-spec.ts` stops asking a |
| 11 | + * running daemon for its fingerprint on the installed side of that line). |
| 12 | + */ |
| 13 | +test('an installed package root is not a source checkout', () => { |
| 14 | + const root = mkdtempForTestSync('agent-device-installed-root-'); |
| 15 | + try { |
| 16 | + fs.writeFileSync(path.join(root, 'package.json'), '{"name":"agent-device"}\n', 'utf8'); |
| 17 | + fs.mkdirSync(path.join(root, 'dist', 'src', 'internal'), { recursive: true }); |
| 18 | + fs.writeFileSync(path.join(root, 'dist', 'src', 'internal', 'daemon.js'), '', 'utf8'); |
| 19 | + |
| 20 | + assert.equal(isSourceCheckoutProjectRoot(root), false); |
| 21 | + } finally { |
| 22 | + fs.rmSync(root, { recursive: true, force: true }); |
| 23 | + } |
| 24 | +}); |
| 25 | + |
| 26 | +test('a checkout carrying the daemon source is a source checkout', () => { |
| 27 | + const root = mkdtempForTestSync('agent-device-source-root-'); |
| 28 | + try { |
| 29 | + fs.writeFileSync(path.join(root, 'package.json'), '{"name":"agent-device"}\n', 'utf8'); |
| 30 | + fs.mkdirSync(path.join(root, 'src'), { recursive: true }); |
| 31 | + fs.writeFileSync(path.join(root, 'src', 'daemon.ts'), 'export {};\n', 'utf8'); |
| 32 | + |
| 33 | + assert.equal(isSourceCheckoutProjectRoot(root), true); |
| 34 | + } finally { |
| 35 | + fs.rmSync(root, { recursive: true, force: true }); |
| 36 | + } |
| 37 | +}); |
| 38 | + |
| 39 | +test('a root with neither a manifest nor a daemon source is neither', () => { |
| 40 | + const root = mkdtempForTestSync('agent-device-bare-root-'); |
| 41 | + try { |
| 42 | + assert.equal(isSourceCheckoutProjectRoot(root), false); |
| 43 | + |
| 44 | + fs.mkdirSync(path.join(root, 'src'), { recursive: true }); |
| 45 | + fs.writeFileSync(path.join(root, 'src', 'daemon.ts'), 'export {};\n', 'utf8'); |
| 46 | + assert.equal( |
| 47 | + isSourceCheckoutProjectRoot(root), |
| 48 | + false, |
| 49 | + 'a daemon source alone does not make a checkout', |
| 50 | + ); |
| 51 | + } finally { |
| 52 | + fs.rmSync(root, { recursive: true, force: true }); |
| 53 | + } |
| 54 | +}); |
| 55 | + |
| 56 | +test('this checkout is the source checkout its resolver reports', () => { |
| 57 | + assert.equal(isSourceCheckoutProjectRoot(resolveAgentDeviceProjectRoot(process.cwd())), true); |
| 58 | +}); |
0 commit comments