Files
orca/config/scripts/verify-cli-require-resolution.test.mjs
T
Jinjing e9063f106d Move agent-catalog schema migration to shared for CLI
Why: CLI's offline settings writes need AGENT_CATALOG_SCHEMA_VERSION but
cannot import from out/main (electron-vite removes it during rebuild).
Extract pure schema logic to src/shared, FS-bound backup operations to
src/main. Add CLI require-resolution verification to catch MODULE_NOT_FOUND
at build time instead of runtime. Fix hydration-time purge to defer
incomplete repos: was deleting all local owners on remote-only hydration
(incident 2026-07-19).
2026-09-01 03:53:17 -07:00

85 lines
3.1 KiB
JavaScript

import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
import { verifyCliRequireResolution } from './verify-cli-require-resolution.mjs'
const tempDirs = []
function makeProject(files) {
const projectDir = mkdtempSync(path.join(tmpdir(), 'orca-cli-requires-'))
tempDirs.push(projectDir)
for (const [relativePath, content] of Object.entries(files)) {
const filePath = path.join(projectDir, relativePath)
mkdirSync(path.dirname(filePath), { recursive: true })
writeFileSync(filePath, content, 'utf8')
}
return projectDir
}
afterEach(() => {
while (tempDirs.length > 0) {
rmSync(tempDirs.pop(), { recursive: true, force: true })
}
})
describe('verifyCliRequireResolution', () => {
it('passes when every relative require resolves in out/', () => {
const projectDir = makeProject({
'out/cli/index.js': `const a = require("./handlers/agent-hooks");`,
'out/cli/handlers/agent-hooks.js': `require("../../shared/constants");`,
'out/shared/constants.js': 'module.exports = {}'
})
const result = verifyCliRequireResolution({ projectDir })
expect(result.missing).toEqual([])
expect(result.checkedFiles).toBe(3)
})
it('reports a CLI require of a main module electron-vite removed', () => {
// The 1.4.150-rc.1.perf shape: tsc emitted the module, electron-vite's
// out/main clean deleted it, and the package shipped without it.
const projectDir = makeProject({
'out/cli/handlers/agent-hooks.js': `require("../../main/agent-launch/agent-catalog-schema-migration");`
})
const result = verifyCliRequireResolution({ projectDir })
expect(result.missing).toEqual([
{
from: path.join('out', 'cli', 'handlers', 'agent-hooks.js'),
specifier: '../../main/agent-launch/agent-catalog-schema-migration'
}
])
})
it('follows transitive requires out of out/cli into out/shared', () => {
const projectDir = makeProject({
'out/cli/index.js': `require("../shared/session-key");`,
'out/shared/session-key.js': `require("../main/deleted-by-clean");`
})
const result = verifyCliRequireResolution({ projectDir })
expect(result.missing).toEqual([
{ from: path.join('out', 'shared', 'session-key.js'), specifier: '../main/deleted-by-clean' }
])
})
it('resolves directory index and json targets and ignores package requires', () => {
const projectDir = makeProject({
'out/cli/index.js': `
require("./handlers");
require("./config.json");
require("commander");
`,
'out/cli/handlers/index.js': 'module.exports = {}',
'out/cli/config.json': '{}'
})
const result = verifyCliRequireResolution({ projectDir })
expect(result.missing).toEqual([])
})
it('skips when out/cli has not been built', () => {
const projectDir = makeProject({ 'out/main/index.js': '' })
const result = verifyCliRequireResolution({ projectDir })
expect(result.skipped).toBe(true)
expect(result.missing).toEqual([])
})
})