mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
e3c44ea4c3
* test(vitest): record the subprocess-stub kill-criterion outcome
#1823's kill criterion was met (~64 consecutive genuine Coverage-job
completions since dbc4f2f955 with zero timeout-shaped failures), so
the subprocess-stub project is gone for good rather than mid-experiment.
Rewrite the vitest.config.ts comments to state that resolved outcome
instead of framing it as an ongoing revert-on-first-failure trial.
* test: remove retired subprocess project traces
* test: model the active fuzz worker project
110 lines
3.6 KiB
TypeScript
110 lines
3.6 KiB
TypeScript
// Unit-resolution tests, kept to the cases where a mistake would OVER-credit a lane.
|
|
//
|
|
// Under-credit corrects itself: the real tree is audited on every PR, so a command
|
|
// the model fails to read shows up as an unowned check within one run. Over-credit
|
|
// is the dangerous direction — it reads as coverage that is not there — so those are
|
|
// the shapes pinned here, plus the two real-tree facts the unit vocabulary exists for.
|
|
|
|
import { execFileSync } from 'node:child_process';
|
|
import assert from 'node:assert/strict';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
import { loadModel, scriptUnits, unitCovers } from './model.ts';
|
|
|
|
const repoRoot = path.resolve(import.meta.dirname, '../..');
|
|
const tracked = execFileSync('git', ['ls-files'], {
|
|
cwd: repoRoot,
|
|
encoding: 'utf8',
|
|
})
|
|
.split('\n')
|
|
.filter(Boolean);
|
|
const model = loadModel(repoRoot, tracked);
|
|
|
|
const scriptModel = (scripts: Record<string, string>) => ({
|
|
scripts,
|
|
vitestProjects: ['unit-core', 'fuzz-worker'],
|
|
opaque: {},
|
|
});
|
|
|
|
test('an env prefix does not hide the command behind it', () => {
|
|
assert.deepEqual(
|
|
scriptUnits(
|
|
'build:x',
|
|
scriptModel({
|
|
'build:x': 'AGENT_DEVICE_XCUITEST_PLATFORM=ios sh ./scripts/build.sh',
|
|
}),
|
|
),
|
|
['script:build:x'],
|
|
);
|
|
});
|
|
|
|
test('a filtered Vitest run does not credit the whole project', () => {
|
|
const units = scriptUnits(
|
|
'docs',
|
|
scriptModel({
|
|
docs: 'vitest run --project unit-core src/__tests__/command-doc-coverage.test.ts',
|
|
}),
|
|
);
|
|
assert.deepEqual(units, ['vitest:unit-core@src/__tests__/command-doc-coverage.test.ts']);
|
|
assert.equal(
|
|
unitCovers('vitest:unit-core', units[0] as string),
|
|
true,
|
|
'the whole project covers the file',
|
|
);
|
|
assert.equal(
|
|
unitCovers(units[0] as string, 'vitest:unit-core'),
|
|
false,
|
|
'the file does not cover the project',
|
|
);
|
|
});
|
|
|
|
test('a bare Vitest run spans every configured project', () => {
|
|
assert.deepEqual(scriptUnits('all', scriptModel({ all: 'vitest run --coverage' })), [
|
|
'vitest:unit-core',
|
|
'vitest:fuzz-worker',
|
|
]);
|
|
});
|
|
|
|
test('a negated --project subtracts from the configured set, so the skipped one is not credited', () => {
|
|
assert.deepEqual(
|
|
scriptUnits('cov', scriptModel({ cov: 'vitest run --coverage --project=!fuzz-worker' })),
|
|
['vitest:unit-core'],
|
|
);
|
|
});
|
|
|
|
// A negated `--project` leg followed by a nested script must preserve both
|
|
// indirections, or the lane stops owning the project handed to that leg.
|
|
test('split coverage commands together still own every project', () => {
|
|
assert.deepEqual(
|
|
scriptUnits(
|
|
'test:coverage:ci',
|
|
scriptModel({
|
|
'test:coverage:ci': 'vitest run --coverage --project=!fuzz-worker && pnpm test:fuzz-worker',
|
|
'test:fuzz-worker': 'vitest run --project fuzz-worker',
|
|
}),
|
|
),
|
|
['vitest:unit-core', 'vitest:fuzz-worker'],
|
|
);
|
|
});
|
|
|
|
test('aggregates expand transitively, so a lane running the aggregate owns its parts', () => {
|
|
const units = scriptUnits(
|
|
'check:all',
|
|
scriptModel({
|
|
'check:all': 'pnpm lint && pnpm test:unit',
|
|
lint: 'oxlint .',
|
|
'test:unit': 'vitest run --project unit-core',
|
|
}),
|
|
);
|
|
assert.deepEqual(units, ['script:lint', 'vitest:unit-core']);
|
|
});
|
|
|
|
test('`node --test` globs expand against the tree, which is how test:smoke is owned', () => {
|
|
const smoke = scriptUnits('test:smoke', model);
|
|
const integration = scriptUnits('test:integration:node', model);
|
|
assert.ok(smoke.length > 1, 'the smoke glob must resolve to real files');
|
|
for (const unit of smoke) {
|
|
assert.ok(integration.includes(unit), `${unit} must be covered by the integration glob`);
|
|
}
|
|
});
|