Skip to content

Latest commit

 

History

History
140 lines (107 loc) · 7.72 KB

test_deepwiki.md

File metadata and controls

140 lines (107 loc) · 7.72 KB

test_deepwiki.sh

Revision: 2 Last modified: 2026-12-04T16:05:45Z

Overview

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:

  1. bash -n every shell file in scripts/deepwiki/, so a syntax error can never reach a consumer as a broken hook step.
  2. 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.1 port — so the tests exercise the real transport code (status codes, the mandatory dual Accept header, 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.

The honest boundary (§11.4.289)

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.

Prerequisites

  • bash, python3 >= 3.10 (stdlib only).
  • scripts/testing/verify_readme_badge_images.sh for 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.

Usage examples

# 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

Coverage

62 cases across seven groups. Every one is a named, individually selectable assertion.

  • Detection contract (17) — INDEXED/NOT_INDEXED/CANNOT_DETERMINE/INVALID_IDENTIFIER exit codes; malformed identifiers never reach the network; a three-segment id is rejected locally; unknown prose is CANNOT_DETERMINE and never a negative; missing structuredContent, a wrong-repo positive, a malformed frame, an empty frame, a JSON-RPC error, HTTP 406 and HTTP 500 are all CANNOT_DETERMINE; unreachable is CANNOT_DETERMINE; a timeout is bounded; both Accept types 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 .disabled recipe is skipped; a declared repo = outranks remotes; duplicate mirrors collapse to one; no remotes and no recipes yields none; a non-git directory is CANNOT-DETERMINE.
  • Badge shape (3) — the canonical string; the emitted badge passes the real verify_readme_badge_images.sh --offline; and the historical deepwiki.com/badge.svg defect 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) — detect exit codes through the real shell wrapper; a service outage never returns a non-zero exit; usage error is 64; candidates prints the documented order.
  • Shell hygiene (1) — every .sh in 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.

Edge cases

  • Running as root — the read-only-README case cannot be exercised when chmod cannot deny write, so it prints SKIP reason=operator_attended rather than pretending to have tested it.
  • A stale deepwiki module — the driver pops sys.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 finally block 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 raises BrokenPipeError/ConnectionResetError, which it swallows: a dead socket there is the expected outcome of the test, not a failure.
  • --only matching nothing — exit 64 with a message, never a silent green over zero cases.

Internal behaviour

  1. Resolve HERE from BASH_SOURCE, check python3 exists (missing ⇒ exit 64).
  2. bash -n each scripts/deepwiki/*.sh; any failure prints FAIL 0/0 cases shell-parse failed and exits 1.
  3. exec the 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.

Related scripts

  • scripts/deepwiki/mutation_test_deepwiki.sh — proves these cases can fail (§1.1).
  • scripts/deepwiki/deepwiki.sh — the CLI the cli_* 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.

Last verified

2026-12-05 — bash scripts/deepwiki/test_deepwiki.sh → test_deepwiki: PASS 62/62 cases 0 failed (exit 0).