Skip to content

doctest assertions - #6794

Merged
fubhy merged 2 commits into
mainfrom
doctest-assertions
Jul 30, 2026
Merged

doctest assertions#6794
fubhy merged 2 commits into
mainfrom
doctest-assertions

Conversation

@fubhy

@fubhy fubhy commented Jul 30, 2026

Copy link
Copy Markdown
Member
  • Fix tests
  • Add convention based output assertion for documentation tests

@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bd05188

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@effect/doctest Patch
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-slopcop effect-slopcop Bot added 4.0 enhancement New feature or request labels Jul 30, 2026
@fubhy
fubhy force-pushed the doctest-assertions branch from d54c49c to d90c8b1 Compare July 30, 2026 21:39

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ One minor issue — generated code passes dead arguments to wrap.

Reviewed changes

  • Source.ts: Adds expected field to Snippet and an outputPattern regex that extracts standalone // > comment markers from snippet source, computing expected output as newline-joined captured text.
  • Runtime.ts (new): Implements the test export that registers a Vitest test, optionally intercepting all console.* methods via a captured node:console instance with colorMode: false and asserting captured output against the expected string.
  • Plugin.ts: Collector module generation now imports test from @effect/doctest/Runtime and passes the expected string as a third argument. The lazy import of Source is replaced with a direct static import. Renames examplesnippet throughout.
  • Protocol.ts: Renames examplePrefix/exampleIdsnippetPrefix/snippetId and updates the kind union and all callers.
  • Runner.ts: Simplifies wrap by removing the include/root filtering — all files now go through content scanning for the import.meta.vitest marker, and the vite createFilter import is dropped.
  • Test reorganization: The monolithic Doctest.test.ts is split into focused test files (Source.test.ts, Protocol.test.ts, Plugin.test.ts, Runtime.test.ts). The old Runner.test.ts is removed since its tested parameters no longer exist.
  • Docs & config: README.md, .patterns/jsdoc.md, and AGENTS.md updated to document the // > convention and new pnpm doctest watch behavior. package.json doctest script drops run (now matches pnpm test behavior). Array.ts converts one example comment to an output assertion.

Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:

  • packages/tools/doctest/src/Plugin.ts:30 (RIGHT) — line 30 (RIGHT) is not inside a diff hunk

Pullfrog  | Fix it ➔View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@fubhy
fubhy force-pushed the doctest-assertions branch from d90c8b1 to 5baaa70 Compare July 30, 2026 21:43

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes (incremental — d54c49cd90c8b1)

  • Plugin.ts: Removes the runnerModule function entirely. Instead of generating a runner wrapper file, the config hook now directly sets test.runner to "@effect/doctest/Runner" when no runner is already configured. Imports for node:fs, node:crypto, node:path, UserConfig, and defaultInclude are cleaned up. Adds enforce: "pre" and perEnvironmentWatchChangeDuringDev: true.
  • Plugin.test.ts: Adds two new tests verifying the config hook sets the default runner and preserves an existing custom runner.
  • README.md: Adds documentation on source file collection via includeSource and runner configuration behavior.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes (incremental — d90c8b15baaa70)

  • Plugin.ts: Removes the unused import type { TestUserConfig } from vitest/config.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@fubhy
fubhy force-pushed the doctest-assertions branch from 5baaa70 to bd05188 Compare July 30, 2026 21:46
@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 6.63 KB 6.63 KB 0.00 KB (0.00%)
batching.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
brand.ts 6.31 KB 6.31 KB 0.00 KB (0.00%)
cache.ts 10.12 KB 10.12 KB 0.00 KB (0.00%)
config.ts 20.04 KB 20.04 KB 0.00 KB (0.00%)
differ.ts 19.93 KB 19.93 KB 0.00 KB (0.00%)
http-client.ts 20.94 KB 20.94 KB 0.00 KB (0.00%)
logger.ts 10.28 KB 10.28 KB 0.00 KB (0.00%)
metric.ts 8.55 KB 8.55 KB 0.00 KB (0.00%)
optic.ts 7.33 KB 7.33 KB 0.00 KB (0.00%)
pubsub.ts 14.26 KB 14.26 KB 0.00 KB (0.00%)
queue.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schedule.ts 10.27 KB 10.27 KB 0.00 KB (0.00%)
schema-class.ts 18.86 KB 18.86 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 28.67 KB 28.67 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 24.99 KB 24.99 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.95 KB 12.95 KB 0.00 KB (0.00%)
schema-string.ts 10.65 KB 10.65 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.85 KB 14.85 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 21.66 KB 21.66 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.08 KB 24.08 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.91 KB 18.91 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.73 KB 18.73 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.59 KB 18.59 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.33 KB 22.33 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.25 KB 19.25 KB 0.00 KB (0.00%)
schema.ts 18.12 KB 18.12 KB 0.00 KB (0.00%)
stm.ts 12.05 KB 12.05 KB 0.00 KB (0.00%)
stream.ts 9.37 KB 9.37 KB 0.00 KB (0.00%)

@fubhy
fubhy merged commit 8e89cc6 into main Jul 30, 2026
17 checks passed
@fubhy
fubhy deleted the doctest-assertions branch July 30, 2026 21:52

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes (incremental — prior Pullfrog review at 5baaa70)

  • Test reorganization: Monolithic Doctest.test.ts replaced with focused test files — Source.test.ts, Protocol.test.ts, Plugin.test.ts, and Runtime.test.ts. Old Runner.test.ts removed since its tested API surface no longer exists. Each test file uses assert from @effect/vitest and standalone it blocks.
  • Runtime.ts (new): Introduces test(name, run, expected?) that registers a Vitest test. When expected is defined, it intercepts all console.* methods via a fresh node:console instance with colorMode: false, writes captured output to a single Writable stream, restores originals in finally, and asserts the joined output (trailing \r?\n stripped) against the expected string.
  • Source.ts: Adds expected: string | undefined to Snippet and a new outputPattern regex that extracts standalone // > comment markers from snippet source. Markers are matched after the JSDoc * prefix is stripped (for JSDoc format) or directly (for Markdown), then joined with \n to form the expected output. The source field retains markers as harmless comments. Removes globalThis. from Array.from calls.
  • Plugin.ts: collectorModule now imports test from @effect/doctest/Runtime and passes JSON.stringify(snippet.expected) as a third argument — undefined expected values serialize to the JavaScript undefined literal, correctly skipping interception. Lazy import("./Source.ts") replaced with a direct static import. byFile renamed to store. examplesnippet throughout. import type { TestUserConfig } is back (dropped earlier, now needed for satisfies).
  • Protocol.ts: examplePrefixsnippetPrefix, exampleIdsnippetId, kind union updated to "collector" | "snippet". No behavioral change.
  • Runner.ts: wrap signature simplified — include and root parameters removed, createFilter import dropped. Runner now scans all collected files for import.meta.vitest rather than applying a separate include filter.
  • Docs & config: README.md adds an "Expected console output" section documenting the // > convention. .patterns/jsdoc.md adds a bullet in "Example Best Practices". AGENTS.md notes that a bare pnpm doctest also runs in watch mode. package.json doctest script drops run. Array.ts converts one example comment to an output assertion.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant