Repository navigation
Expand file tree
/
Copy pathci-changes.test.mjs
More file actions
101 lines (98 loc) · 6 KB
/
Copy pathci-changes.test.mjs
File metadata and controls
101 lines (98 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import test from 'node:test'
import assert from 'node:assert/strict'
import { execFileSync } from 'node:child_process'
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import { changedChecks, classifyChanges } from './ci-changes.mjs'
import { checkResults } from './ci-check-result.mjs'
const enabled = paths => Object.entries(classifyChanges(paths)).filter(([, value]) => value).map(([name]) => name)
test('frontend changes do not select Rust', () => {
assert.deepEqual(enabled(['ui/src/App.tsx', 'ui/pnpm-lock.yaml']), ['frontend'])
})
test('Rust and embedded resources select all existing Rust platforms', () => {
for (const path of ['src/main.rs', 'crates/orx-host/src/main.rs', 'tests/compute_cli.rs', 'Cargo.lock', 'build.rs', 'agent-skills/orx-compute/SKILL.md', 'demo/nanochat/base/file.txt', 'SYSTEM_PROMPT.md', 'SKILL.md']) {
assert.deepEqual(enabled([path]), ['rust', 'windows', 'linux', 'macos'], path)
}
})
test('platform files select corresponding checks', () => {
assert.deepEqual(enabled(['windows/launcher/src/main.rs']), ['windows'])
assert.deepEqual(enabled(['linux/OpenResearch.png']), ['linux'])
assert.deepEqual(enabled(['macos/Info.plist']), ['rust', 'macos'])
})
test('helper tests are independent and combine with other changes', () => {
assert.deepEqual(enabled(['dev.ts']), ['dev'])
assert.deepEqual(enabled(['scripts/dev.test.ts', 'scripts/test_orx_chart.py', 'scripts/orx-chart.test.mjs', 'scripts/release_notes.py', 'ui/package.json']), ['frontend', 'dev', 'chart', 'release_notes'])
})
test('docs skip builds, workflow changes and unknown files select all', () => {
assert.deepEqual(enabled(['README.md', 'docs/linux.md', 'LICENSE', '.github/readme-assets/banner.png', 'macos/DISTRIBUTION.md', 'windows/README.md', 'ui/README.md']), [])
for (const path of ['.github/workflows/ci.yml', 'scripts/ci-changes.mjs', '.cargo/config.toml', 'scripts/build-host.mjs', 'scripts/build-host.test.mjs', 'new-build-input']) assert.equal(enabled([path]).length, 8)
})
test('embedded chart changes also run chart tests', () => {
assert.equal(classifyChanges(['agent-skills/orx-figures/assets/orx_chart.py']).chart, true)
assert.equal(classifyChanges(['tests/contracts/locations.json']).frontend, true)
})
test('diff reports both deleted and added paths for renames', () => {
const calls = []
const checks = changedChecks({ base: 'base', head: 'merge' }, args => {
calls.push(args)
return args[0] === 'diff' ? 'ui/old.ts\0src/new.rs\0' : 'sha\n'
})
assert.equal(checks.frontend, true)
assert.equal(checks.rust, true)
assert.deepEqual(calls[2], ['diff', '--name-only', '--no-renames', '-z', 'base', 'merge', '--'])
})
test('unavailable comparisons and forced runs select everything', () => {
for (const options of [{}, { base: '000000' }, { base: 'missing' }, { forceAll: true }]) {
const checks = changedChecks(options, () => { throw new Error('missing commit') })
assert.equal(Object.values(checks).every(Boolean), true)
}
})
const flags = Object.fromEntries(Object.entries(classifyChanges(['ui/src/App.tsx'])).map(([key, value]) => [key, String(value)]))
const needs = { changes: { result: 'success' }, frontend: { result: 'success' }, e2e: { result: 'success' }, rust: { result: 'skipped' }, windows: { result: 'skipped' }, 'linux-app': { result: 'skipped' }, helpers: { result: 'skipped' } }
test('aggregate accepts intentional skips and successful selected jobs', () => checkResults(needs, flags))
test('aggregate rejects failures, cancellations, missing and unexpectedly skipped jobs', () => {
for (const result of ['failure', 'cancelled', 'skipped', undefined]) assert.throws(() => checkResults({ ...needs, frontend: { result } }, flags))
assert.throws(() => checkResults({ ...needs, rust: { result: 'failure' } }, flags))
assert.throws(() => checkResults({ ...needs, e2e: { result: 'skipped' } }, flags))
assert.throws(() => checkResults({ ...needs, changes: { result: 'failure' } }, flags))
assert.throws(() => checkResults(needs, { ...flags, rust: undefined }))
})
test('embedded JavaScript selects the Rust job that runs its tests, without a frontend build', () => {
for (const path of ['src/commands/desktop_zoom.js', 'src/commands/macos_escape.js', 'src/local/acp/zcode-runtime.cjs']) {
assert.deepEqual(enabled([path]), ['rust', 'windows', 'linux', 'macos'], path)
}
assert.deepEqual(enabled(['agent-skills/orx-figures/assets/orx-chart.html']), ['rust', 'windows', 'linux', 'macos', 'chart'])
})
test('shallow checkouts fetch only the missing comparison commit', () => {
const root = mkdtempSync(join(tmpdir(), 'orx-ci-shallow-'))
const source = join(root, 'source')
const clone = join(root, 'clone')
mkdirSync(source)
const gitAt = cwd => args => execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim()
const git = gitAt(source)
try {
git(['init', '-b', 'main'])
git(['config', 'user.name', 'CI test'])
git(['config', 'user.email', 'ci-test@example.invalid'])
writeFileSync(join(source, 'README.md'), 'base')
git(['add', '.']); git(['commit', '-m', 'base'])
const base = git(['rev-parse', 'HEAD'])
mkdirSync(join(source, 'ui'))
writeFileSync(join(source, 'ui', 'app.ts'), 'changed')
git(['add', '.']); git(['commit', '-m', 'frontend'])
git(['clone', '--depth=1', pathToFileURL(source).href, clone])
const shallow = gitAt(clone)
assert.throws(() => shallow(['cat-file', '-e', base]))
const calls = []
const checks = changedChecks({ base }, args => { calls.push(args); return shallow(args) })
assert.equal(checks.frontend, true)
assert.equal(checks.rust, false)
assert.deepEqual(calls.find(args => args[0] === 'fetch'), ['fetch', '--no-tags', '--depth=1', 'origin', base])
assert.equal(shallow(['rev-parse', '--is-shallow-repository']), 'true')
assert.equal(shallow(['rev-list', '--count', 'HEAD']), '1')
} finally {
rmSync(root, { recursive: true, force: true })
}
})