test: enable v8 coverage instrumentation for 程式碼.js (#107) - #156
Merged
Conversation
Refactor backend test files from new Function() sandbox eval to direct require() so v8 coverage provider can instrument 程式碼.js execution. Changes: - 程式碼.js: add conditional module.exports (no-op in GAS runtime) - backend.test.js: replace sandbox eval with vi.stubGlobal + require() - backendSignatureContracts.test.js: same refactor - businessLogicEdgeCases.test.js: same refactor - wiringContracts.test.js: verify exports via require() instead of parsing factory return block from backend.test.js Result: 程式碼.js coverage 0% → 95.04% lines / 88% functions / 77.2% branches Closes t-20260624113613238229-40473-31 Agend-Agent: cb-team-impl2 Agend-Task: t-20260624113613238229-40473-31 Agend-Branch: test/107-p0-backend-coverage Agend-Issued-At: 2026-06-24T11:37:33.898970+00:00
Owner
Author
✅ VERIFIEDReviewed HEAD: Files Reviewed (5)
Stage 1 — Correctness
Stage 2 — Security (Conditional Export)
Note
Evidence
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactor backend test files from
new Function()sandbox eval to directrequire()so v8 coverage provider can instrument程式碼.jsexecution.Problem
程式碼.jsshowed 0% coverage despite having comprehensive tests inbackend.test.js(170+ test cases). The reason: tests usednew Function()to wrap the source in a sandbox IIFE, which v8 cannot instrument.Solution (方案 B)
程式碼.js: Added conditionalmodule.exportsat the end —typeof moduleguard ensures GAS runtime is unaffected (GAS has nomoduleglobal)new Function()sandbox withvi.stubGlobal()+createRequire()+ module cache invalidation — eachcreateGasEnv()call still gets a fresh evaluation matching the old sandbox behaviorwiringContracts.test.js: Updated to verify exports via directrequire()instead of parsing factory return blockFiles Changed
程式碼.jsmodule.exports+_resetSstest helpertests/unit/backend.test.jsnew Function()→require()+vi.stubGlobal()tests/unit/backendSignatureContracts.test.jstests/unit/businessLogicEdgeCases.test.jstests/unit/wiringContracts.test.jsrequire()verificationResults
All 1142 existing tests pass. No behavioral changes. ESLint 0 errors.
refs #107
follows spec