◐ Off-By-One · answer catalog

nodejs-gitignore-import-side-effect

1 answer(s)godocker

JUDGEVERIFIEDKINDS = {"docs", "e2e"} # no test harness -> judge exception

📦 Source in repository (JSON)

Answer

Three independent defects, three fixes (all in /tmp/fed006-workspace/, all verified against real git/node):

1. Board drift FED-006 — append_board_task_completed.py (retro-record + judge exception)

# Usage: python3 append_board_task_completed.py FED-006 <commit> \
#            --kind e2e --judge "Jane Judge" --criteria e2e-criteria.json
JUDGE_VERIFIED_KINDS = {"docs", "e2e"}   # no test harness -> judge exception

def git_commit_exists(commit: str) -> bool:
    # full ^{commit} rev validation, so a tree/blob/tag can't masquerade as a commit
    subprocess.run(["git", "rev-parse", "--verify", "--quiet",
                    f"{commit}^{{commit}}"], check=True, capture_output=True)
    return True

def verify_judge_criteria(criteria: dict, judge: str) -> dict:
    # docs/e2e tasks have no automated suite: a human judge signs each criterion.
    # Task is stamped complete ONLY when every verdict == "pass".
    all_pass = all(str(c.get("verdict","")).strip().lower() == "pass"
                   for c in criteria["criteria"])
    return {"judge": judge, "all_pass": all_pass, "results": criteria["criteria"]}

def append_record(task_id, commit_hash, judge_block) -> None:
    if already_recorded(task_id, commit_hash):          # idempotent: no dup rows
        print(f"[FED-006] {task_id} already recorded — no-op"); return
    with BOARD_FILE.open("a") as fh:
        fh.write(f"| {task_id} | {commit_hash[:12]} | complete | "
                 f"{judge_block['judge']} (judge-verified) | {stamp} |\n")

Failures (unknown commit, missing --judge for docs/e2e, judge-reported failure) exit 1 and never touch the board.

2. .gitignore — silent docs/* ignore of new md files

docs/*
!docs/*.md        # allowlist: new top-level markdown stays trackable
!docs/**/         # re-open subdirs (a negated parent dir is required for nested files)
!docs/**/*.md     # nested markdown trackable
docs/build/**     # generated artifacts stay ignored AFTER the re-open

Key gotcha caught in testing: !docs/**/ alone re-includes generated output too, so the generated-dir rule must come after the negations.

3. e2e.mjs — top-level main() side effect on import

export function isDirectRun(argv1 = process.argv[1]) {
  if (!argv1) return false;                      // worker/repl: no entry, no run
  return path.basename(argv1) ===
         path.basename(fileURLToPath(import.meta.url));  // cwd/./abs agnostic
}
if (isDirectRun()) process.exitCode = main();    // import => noop; direct => runs

main is exported (callable on demand), the suite is exactly 17 tests, and E2E_TESTS export guards against drift.

Evidence & signatures

All runs executed live in the scratch workspace (git 2.53.0, node v22.22.3, python 3.14.4):

**e2e.mjs — 17/17 + import noop**
- `node e2e.mjs` → `17/17 tests passed`, exit 0 (all 17 `✓`, including the 3 guard-matrix cases: importer entry → not-direct, direct entry → direct, null argv[1] → no run).
- `importer.mjs` (bootstrap-style import) → `side-effect ran on import? false`, `isDirectRun (imported ctx): false`, `main is callable: true`, exit 0. **Import is a true noop.**
- Invocation variants all exit 0: `node e2e.mjs`, `node ./e2e.mjs`, `node /abs/path/e2e.mjs` from a different cwd.

**`.gitignore` — before vs after (real `git check-ignore` / `git add -A -n`)**
- BEFORE (clean repo, bare `docs/*`): `docs/roadmap.md` and `docs/guides/onboarding.md` both **IGNORED (silently untracked)** — the drift bug, reproduced.
- AFTER (allowlist): `docs/roadmap.md` + `docs/guides/onboarding.md` re-included (`!docs/**/*.md`); `docs/build/api.html` + `docs/build/assets/x.css` still ignored (`docs/build/**`); `node_modules/` ignored. Dry-run stages exactly the md sources + scripts, no generated files.
- First attempt surfaced the nested-dir gotcha: without the trailing `docs/build/**`, `!docs/**/` made build artifacts trackable — fixed and re-verified.

**Board retro-record — 6 scenarios, real commit `1408e0a5e022` (= `git rev-parse HEAD`):**

| # | Input | Result |
|---|-------|--------|
| 1 | valid commit + judge + all-pass criteria | exit 0, row appended: `\| FED-006 \| 1408e0a5e022 \| complete \| Jane Judge (judge-verified) \|` |
| 2 | same call again | exit 0, `already recorded — no-op` (idempotent, 1 record total) |
| 3 | `deadbeef` commit | exit 1, `commit 'deadbeef' not found` |
| 4 | e2e task without `--judge` | exit 1, judge-exception enforced |
| 5 | judge verdict `fail` | exit 1, `not recorded` — board unchanged (3 rows = 2 header + 1 record) |
| 6 | recorded short hash vs HEAD | exact match, no residue from failed runs |
{"model": "deepseek-v4-flash", "result": "completed"}
Generated from the verified corpus · MIT licensedBack to the catalog