Skip to content

Commit d168a94

Browse files
committed
fix(e2e): keep harness reporting reachable and nonblocking
Resolve the CLI root inside its checkout so fixture paths and revision capture use the intended repository. Open agent-provided Friction Logs nonblocking before validating their type, preventing FIFOs from hanging the controller outside actor supervision. Cover both failures through the CLI and real FIFO regression seams. Refs #1534
1 parent f6235d6 commit d168a94

4 files changed

Lines changed: 133 additions & 2 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { execFile } from 'node:child_process'
2+
import { mkdtemp, readFile, rm, stat } from 'node:fs/promises'
3+
import { tmpdir } from 'node:os'
4+
import { join } from 'node:path'
5+
import { fileURLToPath } from 'node:url'
6+
import { promisify } from 'node:util'
7+
import { expect, test, vi } from 'vitest'
8+
9+
const observed = vi.hoisted(() => ({ root: '' }))
10+
vi.mock('../run/real-driver.mjs', () => ({
11+
createRealDriver: (options: { root: string }) => {
12+
observed.root = options.root
13+
return {
14+
provision: async () => {},
15+
installUnmigrated: async () => {},
16+
initializeLegacyData: async () => {},
17+
snapshot: async () => {},
18+
migrate: async () => ({ exitCode: 0 }),
19+
friction: async () => [],
20+
installAppHost: async () => {},
21+
behaviour: async () => [{ id: 'behaviour.cli', passed: true }],
22+
close: async () => {},
23+
}
24+
},
25+
}))
26+
vi.mock('../isolation.mjs', () => ({
27+
createIsolation: () => ({ drain: () => [], stop: async () => {} }),
28+
}))
29+
30+
test('CLI resolves the checkout root and writes a report with its real Fixture App revision', async () => {
31+
const root = fileURLToPath(new URL('../../../', import.meta.url)).replace(
32+
/\/$/,
33+
'',
34+
)
35+
const output = await mkdtemp(join(tmpdir(), 'mh-cli-root-'))
36+
const argv = process.argv
37+
const exitCode = process.exitCode
38+
const diagnostics = vi.spyOn(console, 'error').mockImplementation(() => {})
39+
try {
40+
process.argv = ['node', 'cli.mjs', '--migrator', 'fake', '--output', output]
41+
const expectedRevision = (
42+
await promisify(execFile)('git', ['rev-parse', 'HEAD'], { cwd: root })
43+
).stdout.trim()
44+
let failure: unknown
45+
try {
46+
await import('../run/cli.mjs')
47+
} catch (error) {
48+
failure = error
49+
}
50+
expect(
51+
failure,
52+
'CLI must reach the Run and report stages from the actual checkout',
53+
).toBeUndefined()
54+
expect(observed.root).toBe(root)
55+
expect(
56+
(
57+
await stat(
58+
join(observed.root, 'e2e/migration-harness/fixture/src/app.mjs'),
59+
)
60+
).isFile(),
61+
).toBe(true)
62+
const report = JSON.parse(
63+
await readFile(join(output, 'run-report.json'), 'utf8'),
64+
)
65+
expect(report.manifest.fixtureRevision).toBe(expectedRevision)
66+
expect(report.outcome).toBe('pass')
67+
} finally {
68+
process.argv = argv
69+
process.exitCode = exitCode
70+
diagnostics.mockRestore()
71+
await rm(output, { recursive: true, force: true })
72+
}
73+
})
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { execFile, spawn } from 'node:child_process'
2+
import { mkdir, mkdtemp, rm } from 'node:fs/promises'
3+
import { tmpdir } from 'node:os'
4+
import { join } from 'node:path'
5+
import { promisify } from 'node:util'
6+
import { expect, test } from 'vitest'
7+
8+
test('R3 a Friction Log FIFO is rejected without blocking the controller', async () => {
9+
const output = await mkdtemp(join(tmpdir(), 'harness-friction-fifo-'))
10+
try {
11+
await mkdir(join(output, 'migrator'))
12+
await promisify(execFile)('mkfifo', [
13+
join(output, 'migrator/friction.json'),
14+
])
15+
const driverUrl = new URL('../run/real-driver.mjs', import.meta.url).href
16+
// The blocked open runs in a disposable process so a regression cannot
17+
// strand a libuv worker in the test runner after its timeout.
18+
const script = `
19+
import { createRealDriver } from ${JSON.stringify(driverUrl)};
20+
const driver = createRealDriver({
21+
id: 'fifo', root: ${JSON.stringify(output)}, output: ${JSON.stringify(output)},
22+
command: 'true', isolation: {}, credentials: {},
23+
manifest: { stack: '1.2.1', guideHash: 'guide' }
24+
});
25+
try { await driver.friction(); process.stdout.write('accepted'); }
26+
catch { process.stdout.write('rejected'); }
27+
`
28+
const outcome = await new Promise<string>((resolve, reject) => {
29+
const child = spawn(
30+
process.execPath,
31+
['--input-type=module', '-e', script],
32+
{
33+
stdio: ['ignore', 'pipe', 'pipe'],
34+
},
35+
)
36+
let stdout = ''
37+
let timedOut = false
38+
const timer = setTimeout(() => {
39+
timedOut = true
40+
child.kill('SIGKILL')
41+
}, 1500)
42+
child.stdout.on('data', (data) => {
43+
stdout += data
44+
})
45+
child.on('error', (error) => {
46+
clearTimeout(timer)
47+
reject(error)
48+
})
49+
child.on('close', () => {
50+
clearTimeout(timer)
51+
resolve(timedOut ? 'blocked-open' : stdout)
52+
})
53+
})
54+
expect(outcome).toBe('rejected')
55+
} finally {
56+
await rm(output, { recursive: true, force: true })
57+
}
58+
})

‎e2e/migration-harness/run/cli.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const command = args[args.indexOf('--migrator') + 1]
1212
if (!args.includes('--migrator') || !command)
1313
throw Error('Usage: harness:run --migrator <command>')
1414
const id = randomUUID()
15-
const root = resolve(fileURLToPath(new URL('../../../..', import.meta.url)))
15+
const root = resolve(fileURLToPath(new URL('../../..', import.meta.url)))
1616
const output = resolve(
1717
args.includes('--output')
1818
? args[args.indexOf('--output') + 1]

‎e2e/migration-harness/run/real-driver.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export function createRealDriver({
241241
async friction() {
242242
const file = await open(
243243
resolve(workspace, 'friction.json'),
244-
constants.O_RDONLY | constants.O_NOFOLLOW,
244+
constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK,
245245
)
246246
try {
247247
const stat = await file.stat()

0 commit comments

Comments
 (0)