Round 9 found no blocker and no HIGH. These are its mechanical findings, plus one
correction to the fix it proposed.
The proposed fix for its MEDIUM did NOT work, and I measured it rather than
taking it. Round 9 suggested two assertions to pin the population WIRING —
`TRACKED_SOURCE_PATHS` equals `trackedSources.tracked`, and `listSourceFiles()`
equals `listSourceFilesFrom(rawSourceModules, TRACKED_SOURCE_PATHS)` — reported
as reddening the two survivors. Written and measured: both mutations stayed green
with those assertions in place (44/44). The reason is structural. On a clean
checkout the walk set and the index set ARE the same set — every tracked file is
on disk, nothing untracked exists — so no comparison between the two populations
can tell which one is wired in. It is observable only on a tree that HAS an
untracked source file, which is precisely the tree CI never checks out.
So it is recorded as residual (4) with its measurement and its DIRECTION, rather
than papered over with an assertion that cannot fail. Direction is what makes it
a residual and not a defect: reverting the wiring is fail-NOISY — it reddens a
developer's checkout that has a scratch file, the original #819 complaint — and
cannot hide a call site from the registry. Every blind direction runs through the
population SOURCE, and those are pinned by the cross-check.
Also from round 9:
- The checkout-vs-binary distinction was stated as an either/or in
`docs/testing.md` and the Dockerfile. MEASURED: with `.git` PRESENT and git off
`PATH`, the guard still fails — it needs both. As written it would license a
future "just `COPY .git` and re-enable it", which is round 8's blocker in
reverse. Both now say so explicitly.
- `docs/guard-inventory.md` claimed the partition residual is "checked only by
the plugin's own real-git tests". They catch an unconditional mispartition, not
one keyed on a path pattern. Corrected, and the wiring residual added beside it.
- The file split left two comments pointing at the file the real-git tests are no
longer in, and one saying "every test above" where there is now nothing above.
- A drifting "1259 tests" figure — the class this PR already swept out once.
- The TS/C#-guards scope item had grown into "A, B and C and D and its sibling"
across four over-long lines; rewritten as a four-item list.
Rebased onto b6b3520bd (#874).
Refs: #819
91 lines
4.3 KiB
TypeScript
91 lines
4.3 KiB
TypeScript
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 { afterAll, describe, expect, it } from 'vitest';
|
|
import { type GitRunner, resolveTrackedSourceFiles } from './trackedSourceFiles';
|
|
|
|
/**
|
|
* SEPARATE FILE because these are the only tests in the SPA suite that need the `git` BINARY, not
|
|
* merely a checkout (ersatztv#819).
|
|
*
|
|
* `docker/Dockerfile`'s web-build stage runs on `node:22-bookworm-slim`, which ships no git at all,
|
|
* so this file is excluded there alongside the guard that needs an index. Keeping them apart means
|
|
* that exclusion costs two files rather than the thirteen injected-runner tests in
|
|
* `trackedSourceFiles.test.ts`, which run fine with no git and no repository.
|
|
*
|
|
* Do NOT make these skip when git is missing. A check that answers "could not tell" by passing is a
|
|
* permanent no-op, which is the whole failure mode this plugin exists to avoid.
|
|
*/
|
|
describe('resolveTrackedSourceFiles against a REAL repository (#819)', () => {
|
|
// Every test in the sibling `trackedSourceFiles.test.ts` injects a fake `GitRunner`, which proves
|
|
// the derivation's SHAPE and never that
|
|
// it works against git. `scripts/tests/test_guard_populations_derive_from_git.py` makes exactly
|
|
// this point about its own primitive — "It proves the mechanism by EXECUTING it rather than by
|
|
// recognising its shape — no monkeypatching, no stand-in for git" — and the population this
|
|
// plugin feeds is asserted for completeness, so it earns the same treatment.
|
|
const repos: string[] = [];
|
|
|
|
afterAll(() => {
|
|
for (const dir of repos) {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
function repoWithOneTrackedAndOneUntracked(): string {
|
|
const dir = mkdtempSync(join(tmpdir(), 'etv-819-'));
|
|
repos.push(dir);
|
|
const git = (...args: string[]) => execFileSync('git', ['-C', dir, ...args], { encoding: 'utf8' });
|
|
|
|
git('init', '-q');
|
|
mkdirSync(join(dir, 'src'), { recursive: true });
|
|
writeFileSync(join(dir, 'src', 'tracked.ts'), 'export const a = 1;\n');
|
|
writeFileSync(join(dir, 'src', 'untracked.ts'), 'export const b = 2;\n');
|
|
// STAGED, not committed. `ls-files` reads the INDEX, so a commit adds nothing — and committing
|
|
// makes the fixture depend on the developer's global git config: under a `commit.gpgsign = true`
|
|
// that many people set, `git commit` fails and these tests go red on their machine while CI
|
|
// stays green. That is the very shape #819 exists to remove, so it must not be reintroduced by
|
|
// #819's own tests. `git add` is unaffected by signing.
|
|
git('add', 'src/tracked.ts');
|
|
return dir;
|
|
}
|
|
|
|
it('really separates a tracked file from an identical untracked sibling', () => {
|
|
const result = resolveTrackedSourceFiles(repoWithOneTrackedAndOneUntracked());
|
|
|
|
expect(result.tracked).toEqual(['src/tracked.ts']);
|
|
expect(result.others).toEqual(['src/untracked.ts']);
|
|
expect(result.absentFromDisk).toEqual([]);
|
|
});
|
|
|
|
it('really reports a tracked file deleted from the working tree as absent', () => {
|
|
const dir = repoWithOneTrackedAndOneUntracked();
|
|
rmSync(join(dir, 'src', 'tracked.ts'));
|
|
|
|
const result = resolveTrackedSourceFiles(dir);
|
|
|
|
expect(result.tracked).toEqual(['src/tracked.ts']);
|
|
expect(result.absentFromDisk).toEqual(['src/tracked.ts']);
|
|
});
|
|
|
|
it('really throws outside a repository, rather than returning an empty population', () => {
|
|
const notARepo = mkdtempSync(join(tmpdir(), 'etv-819-bare-'));
|
|
repos.push(notARepo);
|
|
mkdirSync(join(notARepo, 'src'), { recursive: true });
|
|
|
|
// `GIT_CEILING_DIRECTORIES` stops git walking up into an enclosing repository — without it this
|
|
// test depends on where TMPDIR happens to point, and reports the wrong throw when TMPDIR sits
|
|
// inside a checkout.
|
|
const ceiling: GitRunner = (args) =>
|
|
execFileSync('git', [...args], {
|
|
encoding: 'utf8',
|
|
// Same stderr suppression `runGitDefault` sets, for the same reason: without it git's own
|
|
// `fatal: not a git repository` prints on every run of this file.
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
env: { ...process.env, GIT_CEILING_DIRECTORIES: tmpdir() }
|
|
});
|
|
|
|
expect(() => resolveTrackedSourceFiles(notARepo, ceiling)).toThrow(/could not read the git index/);
|
|
});
|
|
});
|