Revision: 2 Last modified: 2026-12-04T16:05:45Z
Entry point for the DeepWiki badge engine's deterministic, hermetic test suite — the command a gate, a reviewer or an operator runs to prove the engine still decides correctly after a change. It is also the command the paired mutation test drives.
It does exactly two things:
bash -nevery shell file inscripts/deepwiki/, so a syntax error can never reach a consumer as a broken hook step.- Run the Python suite (62 cases), which replaces the live DeepWiki MCP endpoint with an in-process loopback
HTTP responder — a real server on an ephemeral
127.0.0.1port — so the tests exercise the real transport code (status codes, the mandatory dualAcceptheader, SSE framing, JSON-RPC shapes) without touching the network beyond loopback.
Modes the responder imitates, each copied from the measured live contract: indexed, notindexed, malformed,
empty, jsonrpc_error, invalid_format, no_structured, wrong_repo, plainjson, http406, http500, and
slow (a responder that sleeps past the client budget). "Unreachable" is a port that is bound and immediately
released, so a connection is refused deterministically rather than depending on the network being down.
These cases prove the classifier and the README writer against a given response. They do not prove that DeepWiki is reachable, that a named repository is indexed, or that the service behaves as measured. Those are live claims and need a live run:
scripts/deepwiki/deepwiki.sh detect <owner/repo>A green suite plus an unproven live probe is exactly the conflation §11.4.289 forbids; the two are never substituted for each other.
bash,python3>= 3.10 (stdlib only).scripts/testing/verify_readme_badge_images.shfor the single cross-check case that runs the repository's own image-host verifier against an emitted badge. That case is what proves the badge shape is legal rather than merely well-formed.- No network. No git binary. No credentials.
# every case, only failures shown
bash scripts/deepwiki/test_deepwiki.sh
# one family of cases, with per-case timings
bash scripts/deepwiki/test_deepwiki.sh --only '^writer_' --verbose
# list the case names
bash scripts/deepwiki/test_deepwiki.sh --list
# a MUTATED library (this is how the paired mutation test drives it)
bash scripts/deepwiki/test_deepwiki.sh --lib-dir /tmp/mutated --only '^writer_noop_when_already_correct$'Exit codes: 0 every selected case passed, 1 at least one failed, 64 usage or a missing interpreter.
The last line is machine-readable:
test_deepwiki: PASS 62/62 cases 0 failed
test_deepwiki: FAIL 61/62 cases 1 failed
62 cases across seven groups. Every one is a named, individually selectable assertion.
- Detection contract (17) —
INDEXED/NOT_INDEXED/CANNOT_DETERMINE/INVALID_IDENTIFIERexit codes; malformed identifiers never reach the network; a three-segment id is rejected locally; unknown prose isCANNOT_DETERMINEand never a negative; missingstructuredContent, a wrong-repo positive, a malformed frame, an empty frame, a JSON-RPC error, HTTP 406 and HTTP 500 are allCANNOT_DETERMINE; unreachable isCANNOT_DETERMINE; a timeout is bounded; bothAccepttypes are sent; a plain-JSON body is tolerated; a non-http(s) endpoint is refused; the control needle blocks a blind negative and permits a genuine one. - Identity resolution (9) — origin fetch URL is the primary identity; six remote URL forms normalise; a
non-GitHub host yields no candidate; the
.git-as-a-file linked-worktree indirection resolves; recipes are ordered primary-then-norm-sorted and a.disabledrecipe is skipped; a declaredrepo =outranks remotes; duplicate mirrors collapse to one; no remotes and no recipes yields none; a non-git directory isCANNOT-DETERMINE. - Badge shape (3) — the canonical string; the emitted badge passes the real
verify_readme_badge_images.sh --offline; and the historicaldeepwiki.com/badge.svgdefect still FAILS that verifier (the golden-bad control, so the verifier is proved non-vacuous). - README writer (17) — insert when absent; append to an existing row; byte-identical no-op; correct a wrong URL; normalise a hand-added alt; collapse duplicates; markers confine the edit; never badge when not indexed; preserve an existing badge on an unreachable service; offline makes no call; non-GitHub-only skips with the host named; CRLF preserved; mixed endings refused; no trailing newline preserved; symlink written through; symlink escaping the root refused; read-only skipped; unparseable README untouched; missing README skipped; a large README changes only the badge line; no file created outside the README; dry run writes nothing.
- Determinism and concurrency (3) — three runs pick the same winner; declaration order cannot change it; a
held lock makes a second run
DEFERRED; three concurrent CLI processes never corrupt the README. - CLI surface (5) —
detectexit codes through the real shell wrapper; a service outage never returns a non-zero exit; usage error is 64;candidatesprints the documented order. - Shell hygiene (1) — every
.shin the directory parses.
The suite is hermetic by construction: it scrubs ambient DEEPWIKI_* variables before any case runs (a
stray variable would silently redirect the engine and make a run non-reproducible), and every fixture is created
under a private temporary directory removed on exit.
- Running as root — the read-only-README case cannot be exercised when
chmodcannot deny write, so it printsSKIP reason=operator_attendedrather than pretending to have tested it. - A stale
deepwikimodule — the driver popssys.modules["deepwiki"]after inserting--lib-dir, so a mutated copy always wins over a cached import. Without that, the mutation harness would silently test the pristine library. - Port exhaustion — each case binds an ephemeral port and closes it; the responder is shut down in a
finallyblock so a failing case cannot leak a listener into the next one. - A client timeout on purpose (
detect_timeout_is_bounded_and_cannot_determine) — the responder's write to a closed socket raisesBrokenPipeError/ConnectionResetError, which it swallows: a dead socket there is the expected outcome of the test, not a failure. --onlymatching nothing — exit64with a message, never a silent green over zero cases.
- Resolve
HEREfromBASH_SOURCE, checkpython3exists (missing ⇒ exit64). bash -neachscripts/deepwiki/*.sh; any failure printsFAIL 0/0 cases shell-parse failedand exits1.execthe Python driver, passing arguments through unchanged, so exit codes and stdout are the driver's own with no wrapper-level transformation.
The driver (test_deepwiki.py) registers cases via a @case("name") decorator, treats an exception as a
failure (never a silent pass), removes its scratch directory in finally, and prints the totals line last.
scripts/deepwiki/mutation_test_deepwiki.sh— proves these cases can fail (§1.1).scripts/deepwiki/deepwiki.sh— the CLI thecli_*cases exercise end to end.scripts/deepwiki/deepwiki.py— the engine under test.scripts/testing/verify_readme_badge_images.sh— invoked read-only by the badge-shape cross-check.docs/scripts/test_deepwiki.md(this file),docs/guides/deepwiki_badge.md.
2026-12-05 — bash scripts/deepwiki/test_deepwiki.sh → test_deepwiki: PASS 62/62 cases 0 failed (exit 0).