Skip to content

fix(tests): give each test run its own temp fixture root - #276

Merged
mgks merged 2 commits into
docmd-io:mainfrom
svallory:up-fix-test-tmp-root
Nov 11, 2026
Merged

mgks merged 2 commits into
docmd-io:mainfrom
svallory:up-fix-test-tmp-root

Conversation

@svallory

@svallory svallory commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

A side fix found while working on #267 (not one of its numbered steps).

Problem:

  • tests/shared.js sets TEST_ROOT = '/tmp/docmd-brute-tests', tests/feature-integration.test.js uses the same fixed dir, and tests/security.test.js uses /tmp/docmd-brute-security. Two test runs on one host (two worktrees, two CI jobs on one runner, a run while another is still going) write into the same fixture dirs and break each other.
  • The dirs are never removed, so a small tmpfs /tmp fills up over time (ENOSPC).

Repro on main: start node tests/runner.js --only=exit-codes twice at once. One run passes, the other fails migrate --help exits 0 and validate --json with no errors exits 0, because setup() wipes a fixture dir the other run is still using. /tmp/docmd-brute-tests is still there afterwards.

Fix:

  • tests/shared.js: TEST_ROOT is created per run with fs.mkdtempSync(path.join(os.tmpdir(), 'docmd-tests-')) and removed on exit, SIGINT and SIGTERM.
  • The process that creates it exports it as DOCMD_TEST_ROOT, so the child test processes the runner spawns reuse their parent run's dir and leave the cleanup to the parent. Running a test file directly still works: it creates and removes its own dir.
  • tests/feature-integration.test.js imports TEST_ROOT from shared.js; tests/security.test.js uses a security/ subdir of it, so its fixtures stay apart as before.
  • New tests/cli-contracts/test-root.test.js, registered as test-root in tests/runner.js.
  • Also, in a separate commit: the host-flag title in tests/runner.js lost two ids from my own tracker (AC-2, AC-15) that slipped in with fix(cli): honour --host in docmd dev and workspace dev #269.

Not changed: tests/security.test.js also uses two fixed canary dirs (/tmp/docmd-openapi-canary, /tmp/docmd-evil-plugin). I left them alone to keep this PR small; happy to move them under the run root in a follow-up.

Type of change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update

How it was verified

test-root checks that the root is directly under os.tmpdir() and named docmd-tests-*, that a second run (fresh process without DOCMD_TEST_ROOT) gets a different root and removes it when it exits, and that a child with DOCMD_TEST_ROOT set reuses the parent root and does not remove it.

Results:

  • node tests/runner.js --only=test-root,exit-codes,plugin-contract,mcp-read-doc,features,security: 321 passed, 0 failed. No docmd-tests-* dir left in the temp dir afterwards.
  • With DOCMD_TEST_ROOT pointed at a known dir, --only=security,features (256 passed) writes the feature fixtures into it and the security fixtures into its security/ subdir, so the spawned test files do use the runner's root.
  • Two node tests/runner.js --only=exit-codes at once: both pass (7 passed each). On main, one of them fails 2 checks.
  • Ctrl-C on a running --only=features run (SIGINT to the process group) removes the run's dir.
  • Mutation-tested: putting back the fixed /tmp/docmd-brute-tests in shared.js fails 4 of the 7 test-root checks.
  • ESLint on the 5 changed files: 0 errors, no new warnings (same per-file warning counts as main).

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (no documented behaviour changes)
  • My changes generate no new warnings

- tests/shared.js hardcoded TEST_ROOT to /tmp/docmd-brute-tests, and feature-integration.test.js and security.test.js hardcoded their own fixed /tmp dirs, so two test runs on one host wrote into the same fixture dirs and broke each other (setup() wipes a dir another run is still using)
- The dirs were never removed, so a small tmpfs /tmp could fill up over time
- TEST_ROOT is now created per run with fs.mkdtempSync(path.join(os.tmpdir(), 'docmd-tests-')) and removed on exit, SIGINT and SIGTERM
- The process that creates it exports it as DOCMD_TEST_ROOT, so child test processes the runner spawns (feature-integration, security) reuse their parent run's dir and leave cleanup to the parent
- feature-integration.test.js imports TEST_ROOT from shared.js; security.test.js uses a security/ subdir of it, keeping its fixtures apart as before
- Add tests/cli-contracts/test-root.test.js (registered in tests/runner.js as test-root): checks the root is under os.tmpdir(), a second run gets a different root and removes it on exit, and a child with DOCMD_TEST_ROOT reuses the parent root without removing it
- The title registered for host-flag in tests/runner.js carried two ids from the author's own tracker (AC-2, AC-15), added by mistake in docmd-io#269
- They mean nothing in this repo, so the title now just says what the test checks
@mgks

mgks commented Nov 11, 2026

Copy link
Copy Markdown
Member

Excellent fix for test concurrency and fixture isolation.

Replacing the static /tmp/docmd-brute-tests with per-run fs.mkdtempSync roots and ensuring automated cleanup on exit/SIGINT solves race conditions during parallel test runs and prevents /tmp accumulation.

Verified and merging!

@mgks
mgks merged commit f8d6f35 into docmd-io:main Nov 11, 2026
1 check passed
mgks added a commit that referenced this pull request Nov 11, 2026
…ture additions

Synchronize working branch 'dev-0.9.10' with 'main' following the review,
security audit, and integration of 6 community pull requests alongside our
static asset root mirroring feature.

Merged Community Contributions:
- PR #271 (@GPT-AGI / Ting Zhang): fix(parser): resolve folder-index links from nested pages
  Fixes relative link resolution for non-index folder references from deep subdirectories.
- PR #274 (@svallory): fix(core): build finds 0 pages when an ancestor folder matches .gitignore
  Confines gitignore matching to repository root and avoids empty builds when parent paths match ignore patterns.
- PR #275 (@svallory): fix(build): keep git tree clean after pnpm -r run build
  Eliminates timestamps from generated plugin registry and ignores pre-built native binaries across architectures.
- PR #276 (@svallory): fix(tests): give each test run its own temp fixture root
  Isolates test fixtures into unique run directories under os.tmpdir() to prevent concurrency collisions.
- PR #272 (@svallory): feat(api,core): plugin actions receive caller context; one shared action host
  Introduces shared ActionHost with caller context (identity, mode, transport, headers without cookies), origin allowlisting, and unified rebuild queue.
- PR #273 (@svallory): feat(core): docmd serve, a production server for the built site
  Adds zero-dependency production HTTP/WS server with gzip compression, security headers (CSP, HSTS, CORS), health check endpoints (/healthz, /livez, /readyz), and SPA / clean URL routing.

Working Branch Features Included:
- feat(core): Zero-config static root asset mirroring
  Copies static assets from 'public/' or 'static/' (and docs/public/) directly to the output root ('site/'), preserving directory structure and files like 'funding.json', 'CNAME', and '.well-known/'. Adds canonical 'static' configuration option with support for boolean or custom directory lists.
- feat(cli): --host flag support for dev and serve commands (defaults to loopback 127.0.0.1 for CWE-1385 protection, configurable to 0.0.0.0 for container / LAN hosting).

Documentation Impact:
- Configuration Reference: Document 'static' setting (boolean | string[]).
- CLI Reference: Document 'docmd serve' command options and '--host' flag.
- Plugin Guide: Document ActionHost caller context and execution modes.
@mgks mgks mentioned this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants