OpenProgram test system

This page defines test categories, directories, dependency boundaries, commands and CI responsibilities. Runtime dependencies determine test levels; product domains follow module names in openprogram/ . Structural migration does not change product behavior; genuine product defects found by tests are fixed and verified in separate batches.

1. Current implementation

There are currently 394 Git-tracked Python test files: 226 unit, 138 component, 14 contracts, 9 integration, 4 e2e and 3 live. Execution-level cases all reside in tests/<layer>/<product-domain>/, with no tracked test files directly at a level root.

Repository contracts enumerate only Git-tracked files. Structural contracts and autouse runtime guards jointly prohibit TestClient, subprocess, sockets, real threads/thread pools, fixed waits and global thread-class replacement in unit tests. CI separately runs contracts, unit on three Python versions, component, integration, non-browser e2e, built-Web browser, Web, CLI, Desktop and coverage.

The remaining structural gap concerns top-level repository constraints, not test levels: prevent new root development scripts, undeclared top-level directories and deleted source paths from returning to active guides.

2. Reference frameworks and responsibility boundaries

References come from official project documentation. The repository retains existing tools; this design adds no general-purpose test runner.

ToolAdopted capabilityNot providedOpenProgram treatment
pytestPython discovery, fixtures, markers, warnings and xfail policiesDoes not execute JavaScript or guarantee fixture process isolationRuns Python contracts, unit, component, integration, e2e and live
pytest-xdistMultiprocess distributionCannot repair global state, background threads or unsafe monkeypatchesEnable only a fixed worker count after isolation fixes and repeated verification
node:testNode 22 built-in assertions, tests and mocksNo real DOM or browser interactionsUse for pure Web TypeScript/JavaScript logic without new dependencies
VitestExisting CLI TypeScript test runnerDoes not cover the Python worker or real browsersRetain only in CLI; do not install another copy for Web
PlaywrightReal browsers, user-visible behavior and cross-page stateDoes not replace unit/component testsReuse the Python browser extra and Playwright-managed Chromium
GitHub ActionsVersion matrices, job isolation and required checksDoes not define test semanticsSeparate jobs by test level using the same local commands

3. Target structure

tests/
  contracts/{repository,security}/
  unit/<product-domain>/
  component/<product-domain>/
  integration/<product-domain>/
  e2e/{agent,context,web}/
  live/{providers,channels}/
  support/
  conftest.py
LevelAllowed dependenciesProhibited dependenciesDefault execution
contractsAST, tracked files, manifest, registry, schemaExternal services; source-text checks used instead of behavioral assertionsEvery PR
unitIn-memory objects, pure functions, local fakes, isolated temporary files for one module; controlled cleanable threads inside production modulesTestClient, sockets, subprocesses, real background threads/thread pools directly created by tests and fixed sleepsPython 3.11/3.12/3.13
componenttmp_path, temporary SQLite, TestClient, fake providers and controlled threadsExternal networks and real credentialsPython 3.12
integrationLoopback HTTP/WS, real subprocesses and multiple production modulesExternal servicesPython 3.12
e2ePublic CLI, real worker, built Web and browserDeveloper’s real HOME and pre-existing build outputsDedicated CI job
liveReal providers, channels and remote servicesOrdinary PR required checksManual or scheduled

When a test meets multiple levels, choose the one with the strongest dependencies. Directories have at most level/product-domain depth. Markers describe only execution capabilities: slow, browser, sandbox, live; do not repeat levels already expressed by directories.

4. Execution and state isolation

5. Web, CLI and desktop

Existing checksTargetDecision
Web security/architecture source checkapps/web/scripts/check-*.mjsRetain only when source structure itself is contractual
Web pure helper behaviorapps/web/tests/*.test.mjs + node:testImport directly and assert inputs/outputs
Web user interactiontests/e2e/web + PlaywrightOperate built pages and observe public behavior
CLI TypeScriptExisting VitestCI runs typecheck, test and build
desktop VM/fake Electrondesktop component checksCI runs the complete npm run check
Real Electronrelease e2eInitial restructuring adds no packaging-test infrastructure

6. CI data flow

Python commands use uv run --locked. Matrix fail-fast is disabled so one version’s failure does not cancel other results. Ordinary PRs do not run live tests. All CI commands also appear in contribution documentation.

7. Adopted, adjusted and rejected

StatusDecisionBoundary
AdoptLevel-first directories, product-domain subdirectories, strict markers, strict xfail, fixed workers and Playwright-managed ChromiumPreserve test semantics and counts during migration
AdjustRetain necessary Web source contracts while migrating pure logic to node:testDo not rewrite all Web checks at once
AdjustInitially generate coverage reports onlySet thresholds from measured data after stabilization
RejectAdding tox/nox, installing Vitest again in Web, -n auto, and arbitrary global coverage thresholdsExisting tools cover requirements, or current isolation is insufficient for stable parallelism
ExcludeWindows-specific tests, packaging and compatibility; keyring/Credential ManagerOutside this test-system restructuring

8. Acceptance criteria

Merge-turn tests own their temporary SessionStore. The fixture registers close immediately after construction, so successful tests, assertion failures, and setup failures drain pending index writes and join store timers before the unit resource guard runs. The guard remains strict; cleanup does not depend on machine speed or a longer timeout.

History-page objects use the local name historyWindow, keeping source checks for browser window access unambiguous. Local-refresh test repositories include the real ASAR permission-restoration helper so version-change rejection is exercised after staging, without weakening the no-installation assertions.

9. Implementation status

Work itemStatusCompletion evidence
Design and baselineCompleteDesign, site build, link checks, clean-checkout baseline and two-stage independent review
Input enumeration and shared stateCompleteGit-owned input enumeration, temporary-HOME cleanup, local fixtures, thread/TLS cleanup; focused and unit regressions plus independent specification/quality reviews passed
Python directory migrationCompleteDirectory/marker migration complete; duplicate HTTP inventory, agentic-context structural-contract false positives and retry isolation fixed. Final required suite: 5356 passed, 10 skipped, 1 xfailed; independent specification/quality reviews passed
Web/CLI/desktopCompleteWeb pure helpers use node:test; component and built-Web/browser e2e are separate. Scheduler view-model has 4 Node unit tests; Web check/build, CLI typecheck/Vitest/build, desktop checks and independent review passed
CI and contribution documentationCompleteTen independent CI results, three-version unit matrix, locked uv, non-browser e2e, complete Web/CLI/desktop/browser commands and contribution-document contracts; independent review passed
Waits, concurrency and large filesCompleteStructural contracts cover resource imports, fixed waits and global thread-class replacement. Unit autouse guards cover direct test thread/thread-pool creation, fixed waits, production-resource teardown and global-state restoration. Seven files with 109 tests actually requiring runners, thread pools or Workflow execution moved to component. Current required selection: 5699 passed, 16 skipped, 1 xfailed
Coverage and final verificationCompleteIn a locked Python 3.12.13 environment, two consecutive serial unit runs each produced 2560 passed, 3 skipped and branch coverage 42.402765%. CI generates/uploads XML before enforcing a 40% floor at six-digit precision. Fixed -n 4 required selection ran three consecutive times with 5699 passed, 16 skipped, 1 xfailed and 0 worker crashes

10. Improvement plan and implementation records

Complete batches sequentially. Each first reproduces failure through a public/shared boundary, fixes the minimum shared cause, runs focused/affected tests, passes independent specification and quality review, then commits. Do not start the next batch before the prior review passes.

BatchScopeExcludeGateStatus
Zero required-suite failuresRemove old channel implementations unused by the registry; correct @function / Agent method structural-contract false positives; isolate retry test stateDo not change managed channel implementations or public APIsAll 4 failing-node checks passed; final required suite: 5356 passed, 10 skipped, 1 xfailed; independent specification/quality reviews passedComplete
Structure and waiting contractsDetect aliased resource imports, thread-class replacement and nonzero asynchronous waits; intercept direct test thread/thread-pool creation; migrate or rewrite actual violationsDo not implement a Python control-flow interpreter or mechanically split tests by line countStructural/runtime contracts passed; unit: 2434 passed, 3 skipped; five migrated component files: 104 passed; independent specification/quality reviews passedComplete
Coverage gateRecord precise branch baseline, set a regression floor and cover only critical missing branchesDo not pursue arbitrary high coverage or duplicate assertions for coverageTwo isolated locked Python 3.12.13 runs each produced unit 2560 passed, 3 skipped, branch baseline 42.402765%. Six-digit 40% floor passed; XML still uploads before floor enforcement; CI contract passedComplete
JavaScript dependency risksAudit Web, CLI and desktop separately; upgrade compatible dependencies and verify lockfileDo not run npm audit fix --force, and do not introduce a new runnerAfter compatible upgrades, Web decreased from 8 high to 5 high, CLI from 4 high + 1 moderate to 1 moderate, and desktop from 5 high + 2 moderate to 2 high. Remaining items require separate compatible migrations to Next/eslint-config-next 16, esbuild 0.28 and Electron 43. All three workspaces passed npm ci and existing check/test/typecheck/buildComplete
Final integration, 2026-08-15Integrate into main as it stood then; run Python, Web, CLI, desktop, browser, docs, examples and diff/status gatesDo not overwrite uncommitted primary-workspace changes or push remotelyHistorical candidate evidence: serial required suite 5370 passed, 10 skipped, 2 deselected, 1 xfailed; fixed -n 4 ran three consecutive times with 5370 passed, 10 skipped, 1 xfailed and 0 worker crashes. Web, CLI, desktop, browser, docs, examples, Ruff and diff-check gates passed; independent specification/quality reviews passedComplete
Structural maintenance, 2026-08-17Clean root development scripts, synchronize paths/directory READMEs, add repository-structure contracts and repair test regressions after main integrationDo not rearrange product modules or overwrite other primary-workspace tasksContracts: 442 passed, 1 skipped; fixed -n 4 ran three times with 5699 passed, 16 skipped, 1 xfailed and 0 worker crashes. Python 3.12 unit coverage twice measured 42.402765%; docs: 503 pages, 0 broken links; complete Desktop npm run check passedAwaiting independent review