Skip to content

refactor(lib): declarative toFinishWith, memoized RunTestResult, shared test registration - #207

Merged
metalwarrior665 merged 3 commits into
masterfrom
claude/practical-ptolemy-kmeb6h
Oct 26, 2026
Merged

metalwarrior665 merged 3 commits into
masterfrom
claude/practical-ptolemy-kmeb6h

Conversation

@metalwarrior665

@metalwarrior665 metalwarrior665 commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

What

A cleanup of the testing library (lib/). The public API is unchanged.

  • toFinishWith is declarative. The new lib/run-checks.ts turns the options into a list of { name, pass, actual, expected } checks. This replaces about 130 lines of hand-built diff arrays and the isWithinInterval function that mutated its arguments. Adding a check is now one entry in that list, and the matcher only formats the failures. The checks are unit-tested (test/unit/run-checks.test.ts). The existing matcher tests are describe.skip because they depend on a fixed run.
  • Shape matchers are table-driven. toBeArray, toBeString and the rest come from one table. This fixes toBeNonEmptyObject throwing on null, the "a array" typo, and [object Object] in messages.
  • RunTestResult memoizes promises. The old if (this.x) return this.x caches refetched empty values (an empty log, a missing INPUT) and fetched twice when called concurrently. A small once() helper now shares one promise per getter and retries after a failure.
  • Fixes getDataset() fails on large datasets: response is more than the Node string limit #169. getDataset() pages through items 10k at a time, so no single response can exceed Node's string limit. toFinishWith still counts the downloaded items, because the dataset info's item count lags the run by 10-20 seconds. A comment in run-checks.ts says so.
  • testActor and testStandbyActor share defineActorTest. That function holds the options merge, the name, the shouldRun rule and the soft-expect wiring, which were duplicated.

Why not more

Several of the issues I looked at depend on decisions that aren't made yet, so I left them alone:

Verification

Type-check, lint, knip, prettier and npm test pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PEKaCaFK2UkrJS9oTw3Tg4

…ed test registration

- toFinishWith evaluates a list of checks (lib/run-checks.ts) instead of hand-building diffs
- shape matchers are table-driven; toBeNonEmptyObject no longer throws on null
- RunTestResult memoizes promises (empty values and concurrent calls no longer refetch)
- getDataset pages through items and toFinishWith counts via getDatasetItemCount, fixing #169
- testActor and testStandbyActor share defineActorTest

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PEKaCaFK2UkrJS9oTw3Tg4
Comment thread lib/run-test-result.ts
Comment on lines +31 to +34
getStatistics = once(async (): Promise<SdkCrawlerStatistics | undefined> => {
const record = await this.getKeyValueStoreClient().getRecord('SDK_CRAWLER_STATISTICS_0');
return record?.value as SdkCrawlerStatistics | undefined;
});

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.

This will be obsolete in v4, might as well change it now #111

Comment thread lib/extend-expect.ts Outdated
toBeObject: ['an object', isObject],
toBeString: ['a string', (actual: unknown) => typeof actual === 'string'],
toBeWholeNumber: ['a whole number', (actual: unknown) => Number.isInteger(actual)],
} as const;

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.

at least plop a satisfies in there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added satisfies.


Generated by Claude Code

@metalwarrior665

Copy link
Copy Markdown
Member Author

Oops, this has been generated by testing a weekly routine (find best things to refactor & optimize) that I tried to see if Claude can catch up to @JuanGalilea. Will tell it to just do a draft

…info count lags the run

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PEKaCaFK2UkrJS9oTw3Tg4

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Undefined numeric options regress existing behavior, and fixed-size dataset pages can still exceed Node’s string limit.

2 open issues
What changed in this PR

This PR refactors the testing library’s matchers, result fetching, and Actor test registration while aiming to preserve the public API.

Changes:

  • Extracts declarative run checks and table-driven shape matchers.
  • Memoizes result-fetching promises and adds dataset pagination to address #169.
  • Shares Actor test registration logic and adds unit tests for checks, caching, and pagination.
File Description
test/​unit/​run-test-result.test.ts Tests caching, retry behavior, and dataset pagination.
test/​unit/​run-checks.test.ts Tests run expectations and charged-event checks.
lib/​run-test-result.ts Adds promise memoization and paginated dataset retrieval.
lib/​run-checks.ts Centralizes declarative run expectation evaluation.
lib/​lib.ts Shares registration logic between standard and standby Actor tests.
lib/​extend-expect.ts Uses table-driven shape matchers and extracted run checks.

Review effort: Balanced

Comment thread lib/run-checks.ts Resolved
Comment thread lib/run-test-result.ts Resolved
…ptions as disabled

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PEKaCaFK2UkrJS9oTw3Tg4
@metalwarrior665
metalwarrior665 merged commit 4500816 into master Oct 26, 2026
11 checks passed
metalwarrior665 pushed a commit that referenced this pull request Oct 26, 2026
… undefined options as disabled

Ports the fixes made in #207 onto this rewrite:
- the dataset info's item count lags the run by 10-20 s, so toFinishWith counts the downloaded items again
- page size 1000
- explicit undefined options disable their checks, as before
- a failed lazy load is retried instead of cached

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PEKaCaFK2UkrJS9oTw3Tg4
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.

getDataset() fails on large datasets: response is more than the Node string limit

5 participants