Skip to content

improve(test): speed up Mattermost send suite - #124114

Merged
steipete merged 1 commit into
mainfrom
steipete/test-suite-performance-pass-15-aug15
Aug 15, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/test-suite-performance-pass-15-aug15

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Resolves avoidable runtime and memory overhead in the Mattermost send test suite. The suite retained per-test vi.resetModules() and dynamic owner imports after its old test-only cache reset was removed, so every test rebuilt the real send and target-resolution module graph.

Why This Change Was Made

The test file now imports the real send and target-resolution owners once, after mocks are installed, while preserving every test and assertion. Default-account tests use a unique botToken namespace per test because the production caches are keyed by base URL and token; cache-bound tests keep their explicit independent tokens. This exercises real production isolation without adding a production seam, clearing caches, weakening assertions, or using timing shortcuts.

The one-time import is deliberately file-scoped. An earlier candidate put beforeAll inside the first describe block, which made a filtered run of the later cache-bound suite fail with sendMessageMattermost is not a function; moving the hook to file scope fixed that filtered path.

User Impact

No product behavior changes. Mattermost's test suite keeps the same 49 tests and production composition while running with materially lower body time, CPU, and peak memory.

Evidence

  • Controlled corrected-shape A/B on the same Blacksmith Testbox (tbx_01m0286f8cx9x8rgrjj1yn93k0, run 31874291639, stopped):
    • wall: 17.955s -> 14.645s (-18.4%)
    • harness: 17.685s -> 14.305s (-19.1%)
    • Vitest: 15.060s -> 11.635s (-22.7%)
    • test body: 4.900s -> 0.524s (-89.3%)
    • import: 9.550s -> 10.500s (+9.9% noise); the real owner graph still imports once
    • CPU user/sys: 20.560s/2.475s -> 16.425s/1.950s
    • peak RSS: 2,388,506 -> 1,394,596 KiB (-41.6%, about 971 MiB)
  • Filtered cache-bound suite: 4/4 passed after the file-scoped hook correction.
  • Constant-token mutation: collapsing the unique namespace to one token caused 6/49 failures through stale channel-second classification; restoring unique production cache keys returned the file to green.
  • Owner and sibling proof: 65/65 passed across the send, target-resolution, real-HTTP loopback, and channel send-loopback tests.
  • Extension boundaries: 28/28 passed across extension-import-boundaries and extension-test-boundary.
  • Fresh current-base changed gate: all 18 steps passed on tbx_01m0297956c23rpb7g2vbc2x9a, run 31875025720, stopped.
  • Targeted formatting and git diff --check passed. Fresh committed-branch autoreview reported no actionable findings.
  • Diff: tests +13/-9; production +0/-0. No changelog, dependency, schema, protocol, baseline, budget, or production seam changes.

@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 15, 2026 08:46
@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost size: XS maintainer Maintainer-authored PR labels Aug 15, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 4:52 AM ET / 08:52 UTC.

ClawSweeper review

What this changes

The PR imports the mocked Mattermost send and target-resolution owners once per file instead of once per test, while assigning each default-account test a distinct cache token.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for normal maintainer handling. The test-only refactor aligns isolation with the real token-keyed cache boundary and has no actionable correctness finding; rebase it onto current main and confirm exact-head checks before merge.

Priority: P3
Reviewed head: be6dbdee0ee82b1861f8dad675716403d4fa6ae0
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, production-boundary-aware test optimization with strong reported validation and no supported defect finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored test-only PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless records focused Testbox validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored test-only PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless records focused Testbox validation.
Evidence reviewed 6 items Production cache boundary: The real send owner keeps module-lifetime lookup maps and derives their namespace from base URL plus bot token, so unique test tokens isolate cache state without a test-only reset seam.
Runtime path: The Mattermost channel runtime calls the same send owner, confirming that the cache boundary exercised by the tests is production behavior.
Patch intent: The supplied PR patch adds a file-scoped import hook and replaces the default token with a per-test namespace; no production file is changed.
Findings None None.
Security None None.

How this fits together

Mattermost sends resolve an account and target, use token-keyed caches for user/channel lookups, then send through the plugin runtime. The changed test suite mocks transport boundaries while exercising those real resolution and cache owners.

flowchart LR
  A[Test mocks] --> B[File-scoped owner import]
  B --> C[Account resolution]
  C --> D[Token-keyed caches]
  D --> E[Send and target logic]
  E --> F[Mock transport assertions]
Loading

Decision needed

Question Recommendation
After a clean rebase, should this maintainer-owned test-suite optimization be merged? Rebase and merge: Rebase onto current main and merge once the exact head passes the focused Mattermost and required CI checks.

Why: The author association and maintainer label require explicit maintainer handling even though the review found no code defect.

Before merge

  • Resolve merge risk (P1) - The branch is behind current main; rebase and use exact-head CI before merge.
  • Resolve merge risk (P1) - The partial clone could not fetch every promised PR/history blob because network name resolution failed, so the final merge check should revalidate the complete branch diff.
  • Complete next step (P2) - This maintainer-owned PR has no mechanical repair to dispatch; rebase and normal maintainer approval are the remaining actions.
Agent review details

Security

None.

PR surface

Tests +4. Total +4 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 13 9 +4
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 13 9 +4

Review metrics

Metric Value Why it matters
Production versus test delta production 0; tests +4 net The cache-isolation optimization remains entirely in the colocated test suite and adds no runtime or public-contract surface.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/mattermost/src/mattermost/send.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the file-scoped import and production-keyed test namespaces, then merge after a clean rebase confirms the focused Mattermost suite and normal exact-head checks.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the file-scoped import and production-keyed test namespaces, then merge after a clean rebase confirms the focused Mattermost suite and normal exact-head checks.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR optimizes test-suite execution rather than repairing a user-facing defect; the body supplies focused before/after Testbox evidence.

Is this the best way to solve the issue?

Yes: using unique values at the real base-URL-plus-token cache key is cleaner than retaining repeated module resets or adding a test-only cache-reset API.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4fc375654d34.

Labels

Label changes:

  • add P3: This is a bounded internal test-performance improvement with no reported runtime behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored test-only PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless records focused Testbox validation.

Label justifications:

  • P3: This is a bounded internal test-performance improvement with no reported runtime behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored test-only PR is exempt from the external-contributor real-behavior-proof gate; its body nevertheless records focused Testbox validation.

Evidence

What I checked:

Likely related people:

  • steipete: Has the most local-history touches across the Mattermost send, target-resolution, and test surfaces, including recent lookup and test-refactor work. (role: recent area contributor; confidence: high; commits: be6dbdee0ee8, 3832074cd982, 6d3eff97a0d5; files: extensions/mattermost/src/mattermost/send.test.ts, extensions/mattermost/src/mattermost/send.ts)
  • NIO: Introduced the outbound-cache cap work that owns the module-level cache behavior this test isolates. (role: introduced cache behavior; confidence: medium; commits: 514829f0e145; files: extensions/mattermost/src/mattermost/send.ts)
  • mikasa: Added the related opaque-target cache work that uses the same account token namespace principle. (role: adjacent cache contributor; confidence: medium; commits: 20e1368787a6; files: extensions/mattermost/src/mattermost/target-resolution.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and confirm the exact head retains the reported focused test and CI results.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Patch-identical after rebase; stable patch id remains 9e6d4aaf82c91205a6723b71cd8c11ff3e85021e. The PR changes one test file only: tests +13/-9, production +0/-0.

Fresh exact-head landing proof for be6dbdee0ee82b1861f8dad675716403d4fa6ae0:

The controlled same-Testbox A/B remains patch-identical: wall -18.4%, Vitest -22.7%, test body -89.3%, CPU user -20.1%, and peak RSS -41.6% (about 971 MiB). Native review artifacts validate as READY FOR /prepare-pr with issueValidation.status=valid and zero findings.

@steipete

Copy link
Copy Markdown
Contributor Author

ClawSweeper’s merge notes are addressed:

  • There are no code or security findings.
  • The full canonical checkout revalidated the complete current-main diff after the review worker’s partial-clone DNS gap: exactly extensions/mattermost/src/mattermost/send.test.ts, tests +13/-9, production +0/-0, with a clean patch check. No Mattermost send owner file changed on main after this branch’s rebase base.
  • The optional rebase Rank-up move is intentionally skipped under the repository’s native landing policy: the patch was already rebased patch-identically onto f4beff12cd5e9c30d2cc847a8fe8d391fb7dfab8, subsequent behind-main drift is advisory, GitHub reports the head mergeable, exact-head CI is green, and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 124114 passed against the current landing state. Rebasing solely for continued unrelated main movement would churn the proven head without changing this patch.
  • The required maintainer decision is satisfied by the authorized maintainer landing, validated native review artifacts (READY FOR /prepare-pr, issueValidation.status=valid, zero findings), and successful native prepare step.

No actionable Rank-up move or finding remains for the merge coordinator.

@steipete
steipete merged commit ee65561 into main Aug 15, 2026
169 of 171 checks passed
@steipete
steipete deleted the steipete/test-suite-performance-pass-15-aug15 branch August 15, 2026 08:57
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

channel: mattermost Channel integration: mattermost maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant