test: add web-backend vitest coverage#1821
Conversation
| beforeEach(() => { | ||
| setRequiredEnv(); | ||
| vi.useFakeTimers(); | ||
| vi.setSystemTime(new Date("2026-05-15T00:00:00.000Z")); | ||
| }); |
There was a problem hiding this comment.
The
setRequiredEnv() call in beforeEach is redundant: importSignedObject() always calls vi.resetModules() first (which clears @cap/env's cached state) and then calls setRequiredEnv() itself before the dynamic import. The beforeEach call fires before the module reset happens, so it's the import-time call inside importSignedObject() that's meaningful. Having the call in both places obscures which one is load-order critical.
| beforeEach(() => { | |
| setRequiredEnv(); | |
| vi.useFakeTimers(); | |
| vi.setSystemTime(new Date("2026-05-15T00:00:00.000Z")); | |
| }); | |
| beforeEach(() => { | |
| vi.useFakeTimers(); | |
| vi.setSystemTime(new Date("2026-05-15T00:00:00.000Z")); | |
| }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/web-backend/src/Storage/SignedObject.test.ts
Line: 32-36
Comment:
The `setRequiredEnv()` call in `beforeEach` is redundant: `importSignedObject()` always calls `vi.resetModules()` first (which clears `@cap/env`'s cached state) and then calls `setRequiredEnv()` itself before the dynamic import. The `beforeEach` call fires before the module reset happens, so it's the import-time call inside `importSignedObject()` that's meaningful. Having the call in both places obscures which one is load-order critical.
```suggestion
beforeEach(() => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-05-15T00:00:00.000Z"));
});
```
How can I resolve this? If you propose a fix, please make it concise.| const [payload, signature] = token.split("."); | ||
| const changedSignature = `${signature?.slice(0, -1)}${ | ||
| signature?.endsWith("A") ? "B" : "A" | ||
| }`; |
There was a problem hiding this comment.
signature is always defined here because createStorageObjectToken always returns a string in the form encodedPayload.signature, and neither segment contains a .. The optional chaining (?.) is misleading — if signature were ever undefined, signature?.slice(0, -1) would evaluate to undefined, and the template literal would produce "undefinedA" or "undefinedB", which coincidentally would still differ from the real signature. Using a non-optional access makes the intent explicit.
| const [payload, signature] = token.split("."); | |
| const changedSignature = `${signature?.slice(0, -1)}${ | |
| signature?.endsWith("A") ? "B" : "A" | |
| }`; | |
| const [payload, signature] = token.split("."); | |
| if (!payload || !signature) throw new Error("unexpected token format"); | |
| const changedSignature = `${signature.slice(0, -1)}${ | |
| signature.endsWith("A") ? "B" : "A" | |
| }`; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/web-backend/src/Storage/SignedObject.test.ts
Line: 67-70
Comment:
`signature` is always defined here because `createStorageObjectToken` always returns a string in the form `encodedPayload.signature`, and neither segment contains a `.`. The optional chaining (`?.`) is misleading — if `signature` were ever `undefined`, `signature?.slice(0, -1)` would evaluate to `undefined`, and the template literal would produce `"undefinedA"` or `"undefinedB"`, which coincidentally would still differ from the real signature. Using a non-optional access makes the intent explicit.
```suggestion
const [payload, signature] = token.split(".");
if (!payload || !signature) throw new Error("unexpected token format");
const changedSignature = `${signature.slice(0, -1)}${
signature.endsWith("A") ? "B" : "A"
}`;
```
How can I resolve this? If you propose a fix, please make it concise.
Summary
@cap/web-backendpackages/web-backendimporterVerification
corepack pnpm install --filter @cap/web-backend... --frozen-lockfile --ignore-scriptscorepack pnpm --filter @cap/web-backend testcorepack pnpm exec biome check packages/web-backend/package.json packages/web-backend/vitest.config.ts packages/web-backend/src/Videos/EffectiveVideoRules.test.ts packages/web-backend/src/Storage/GoogleDrive.test.ts packages/web-backend/src/Storage/SignedObject.test.tscorepack pnpm exec tsc -p packages/web-backend/tsconfig.json --noEmitThis is a focused follow-up for the current architecture and avoids the desktop/utils/sdk scopes already covered by other open testing attempts.
/claim #54
Greptile Summary
This PR introduces Vitest coverage for
@cap/web-backend, adding a config, atestscript, and three test files targetingEffectiveVideoRules,parseVideoIdFromObjectKey, and theSignedObjecttoken helpers.EffectiveVideoRules.test.tstests pure functions against no external state and is clean end-to-end.GoogleDrive.test.tscorrectly uses a static import becauseparseVideoIdFromObjectKeyis env-independent; the assertion logic matches theOption.filterimplementation precisely.SignedObject.test.tsapplies thevi.resetModules()+ dynamic-import pattern to isolate@cap/env's cached state across tests, and the fake-timer expiry boundary check is correct (60_001 mspast a60 sTTL).Confidence Score: 4/5
Safe to merge — the changes are additive test files only, with no modifications to production code paths.
All three test files exercise the correct production logic and would catch real regressions. The only observations are minor style points in SignedObject.test.ts: a redundant setRequiredEnv() in beforeEach and unnecessary optional chaining on a value that is always defined.
packages/web-backend/src/Storage/SignedObject.test.ts has the minor style issues noted; the other test files and config are clean.
Important Files Changed
testscript andvitest ~2.1.9devDependency; straightforward and correctly scopedparseVideoIdFromObjectKeywith a static import; assertions are accurate against the implementationPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "test: add web-backend vitest coverage" | Re-trigger Greptile