Round 8 found a BLOCKER, and it was my verification that was wrong rather than an argument. The previous commit re-armed `npm test` in the web-build stage and excluded the one file that needs a git CHECKOUT. It did not exclude the file added in round 6 that needs the git BINARY: `trackedSourceFiles`' real-repository tests shell out to `git` to prove the derivation by executing it, and `node:22-bookworm-slim` ships no git. So `docker build` would have failed on every push to `main` and every `v*` tag — no image ships. Why I did not catch it: every "gitless replica" I ran deleted `.git` and left the git binary on `PATH`. That reproduces one of the two preconditions. Re-measured with `PATH` stripped, the previous head gives `spawnSync git ENOENT`, `Test Files 1 failed | 116 passed`. The Dockerfile comment stated the right premise — "no `.git`, AND node:22-bookworm-slim ships no git binary" — two lines above the line that only acted on the first half. The real-git block is now its own file, `trackedSourceFiles.realgit.test.ts`, so excluding it costs two tests rather than the thirteen injected-runner ones that run fine with no git at all. Both exclusions are named in the Dockerfile with their DIFFERENT reasons, and with the instruction to verify any change there with the binary off `PATH`. MEASURED in a replica with neither `.git` nor `git`: 117 files / 1225 tests pass, lint, typecheck and build all exit 0. Also from round 8: - `docs/testing.md`'s row asserted the suite "cannot run against an exported tree with no index" and that the Dockerfile "no longer runs it" — both false at the previous head. It now distinguishes the checkout requirement from the binary requirement, which is the distinction the blocker turned on. - Two clauses this PR added had no proof and MEASURED green when disarmed: the trailing-slash restriction in `unaccountedWalkedPaths` (without it every `others` entry becomes a prefix mask) and the plugin's dedupe. Both now have fixtures, and both mutations redden by name. - The dedupe's stated rationale was wrong: duplicates appear on both sides of the ratio the floor computes, so they cancel. Re-stated as tidiness, with the measurement, and "three times" corrected to two-or-three (a both-added conflict has two stages). - Three JSDoc blocks were stacked above one function, so two of them documented functions defined 15 and 50 lines below and attached to the wrong ones. Pure reordering, plus the blank lines that were detaching them. - `vite-env.d.ts` named the wrong mechanism for its loud-failure claim: a renamed field yields an empty Set, caught by the anti-vacuity floor rather than by a throw at first read. - The Dockerfile no longer hardcodes a test-file count that nothing reddens on. Refs: #819
90 lines
4.3 KiB
TypeScript
90 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 above 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/);
|
|
});
|
|
});
|