Skip to content

test: add sdk embed and backend vitest coverage#1835

Open
NguyenCong2k wants to merge 1 commit into
CapSoftware:mainfrom
NguyenCong2k:test-sdk-embed-web-backend
Open

test: add sdk embed and backend vitest coverage#1835
NguyenCong2k wants to merge 1 commit into
CapSoftware:mainfrom
NguyenCong2k:test-sdk-embed-web-backend

Conversation

@NguyenCong2k
Copy link
Copy Markdown

@NguyenCong2k NguyenCong2k commented May 18, 2026

/claim #54

Summary

  • add Vitest test scripts and minimal configs for @cap/sdk-embed and @cap/web-backend
  • cover createEmbedUrl default and optional embed URL generation
  • cover resolveEffectiveVideoRules precedence/inheritance behavior and password hash collection

Verification

  • pnpm --filter @cap/sdk-embed test
  • pnpm --filter @cap/web-backend test
  • pnpm exec biome check packages/sdk-embed/package.json packages/sdk-embed/vitest.config.ts packages/sdk-embed/src/vanilla/cap-embed.test.ts packages/web-backend/package.json packages/web-backend/vitest.config.ts packages/web-backend/src/Videos/EffectiveVideoRules.test.ts

Notes

  • kept scope separate from open PRs covering desktop/utils, env/database, and web-cluster/web-domain/web-api-contract/sdk-recorder

Greptile Summary

This PR adds Vitest unit test scaffolding for @cap/sdk-embed and @cap/web-backend, wiring up vitest ~2.1.9 as a dev dependency and a test script in each package's package.json.

  • cap-embed.test.ts: Two tests for createEmbedUrl — one validates the default URL shape with only required params, the other exercises all optional params (apiBase, autoplay, branding). Both assertions match the source implementation faithfully.
  • EffectiveVideoRules.test.ts: Three tests covering space-setting overrides, inherited password source collection, and collectPasswordHashes filtering. The tests are structurally correct, but the suite does not include a case where videoSettings explicitly sets a flag to false while organizationSettings sets the same flag to true with no space override — leaving the ?? vs || precedence distinction untested.

Confidence Score: 4/5

Safe to merge — adds test infrastructure and test files only; no production code is changed.

All new test assertions correctly mirror the source. The two gaps noted are coverage suggestions rather than incorrect tests.

packages/web-backend/src/Videos/EffectiveVideoRules.test.ts — the precedence and null-password cases could be filled in to give the test suite more confidence against future refactors.

Important Files Changed

Filename Overview
packages/sdk-embed/src/vanilla/cap-embed.test.ts New tests for createEmbedUrl: covers default URL shape and all optional params; assertions match the implementation exactly.
packages/web-backend/src/Videos/EffectiveVideoRules.test.ts New tests for resolveEffectiveVideoRules and collectPasswordHashes; correct assertions but missing coverage for videoSettings/organizationSettings precedence and absent videoPassword.
packages/sdk-embed/vitest.config.ts Minimal vitest config with node environment and correct glob; no issues.
packages/web-backend/vitest.config.ts Identical vitest config to sdk-embed; appropriate node environment for pure-logic tests.
packages/sdk-embed/package.json Added vitest ~2.1.9 devDependency and test script; removed empty dependencies block.
packages/web-backend/package.json Added vitest ~2.1.9 devDependency and test script; @cap/env moved to its correct sorted position in dependencies.
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
packages/web-backend/src/Videos/EffectiveVideoRules.test.ts:8-42
**Precedence between `videoSettings` and `organizationSettings` not covered**

The test name promises to exercise "space settings override video and organization defaults," but the branch where `videoSettings` explicitly sets a flag to `false` while `organizationSettings` sets the same flag to `true` (with no space override) is never reached. For `disableCaptions`, the space provides an override so the `videoSettings?.[key] ?? organizationSettings?.[key]` line is bypassed entirely.

Because of `??`, an explicit `false` in `videoSettings` correctly shadows the org-level `true`. If that operator were ever changed to `||`, this test suite would still pass — making it possible to silently invert the intended "video setting wins" precedence. Consider adding a case where a space array is empty (or excludes a key), `videoSettings.someKey = false`, and `organizationSettings.someKey = true`, and asserting that the result is `false`.

### Issue 2 of 2
packages/web-backend/src/Videos/EffectiveVideoRules.test.ts:61-75
**No test for absent / null `videoPassword`**

Only the "happy path" (a truthy `videoPassword`) is covered. The function also handles `videoPassword` being `undefined` or `null` via `...(videoPassword ? [videoPassword] : [])`. Adding a test case where `videoPassword` is omitted or `null` would confirm the guard works, especially if the function signature changes in the future.

Reviews (1): Last reviewed commit: "test: add sdk embed and backend coverage" | Re-trigger Greptile

Greptile also left 2 inline comments on this PR.

Copilot AI review requested due to automatic review settings May 18, 2026 02:51
@superagent-security superagent-security Bot added the contributor:verified Contributor passed trust analysis. label May 18, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Vitest setup and initial unit tests to the @cap/sdk-embed and @cap/web-backend packages as part of the broader effort to introduce a testing framework across the monorepo (issue #54).

Changes:

  • Adds vitest devDependency, a minimal vitest.config.ts, and a test script to both packages/sdk-embed and packages/web-backend.
  • Adds cap-embed.test.ts covering createEmbedUrl default URL and optional autoplay/branding parameters.
  • Adds EffectiveVideoRules.test.ts covering resolveEffectiveVideoRules inheritance/precedence, inherited password sources, and collectPasswordHashes filtering.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/sdk-embed/package.json Adds test script and vitest devDependency; also reorders deps alphabetically.
packages/sdk-embed/vitest.config.ts Minimal Vitest config (node env, src/**/*.test.ts).
packages/sdk-embed/src/vanilla/cap-embed.test.ts Unit tests for createEmbedUrl.
packages/web-backend/package.json Adds test script and vitest devDependency; moves @cap/env to alphabetical position.
packages/web-backend/vitest.config.ts Minimal Vitest config.
packages/web-backend/src/Videos/EffectiveVideoRules.test.ts Unit tests for resolveEffectiveVideoRules and collectPasswordHashes.
pnpm-lock.yaml Lockfile updates for new Vitest devDependency and incidental transitive bumps.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +42
it("lets space settings override video and organization defaults", () => {
const rules = resolveEffectiveVideoRules({
videoSettings: {
disableCaptions: false,
disableComments: true,
},
organizationSettings: {
disableCaptions: true,
disableTranscript: true,
},
spaces: [
{
id: "space-1",
name: "Engineering",
settings: {
disableCaptions: true,
disableSummary: true,
},
},
],
});

expect(rules.settings).toMatchObject({
disableCaptions: true,
disableComments: true,
disableSummary: true,
disableTranscript: true,
});
expect(rules.inheritedSettings.disableCaptions).toEqual([
{ id: "space-1", name: "Engineering" },
]);
expect(rules.inheritedSettings.disableSummary).toEqual([
{ id: "space-1", name: "Engineering" },
]);
});
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.

P2 Precedence between videoSettings and organizationSettings not covered

The test name promises to exercise "space settings override video and organization defaults," but the branch where videoSettings explicitly sets a flag to false while organizationSettings sets the same flag to true (with no space override) is never reached. For disableCaptions, the space provides an override so the videoSettings?.[key] ?? organizationSettings?.[key] line is bypassed entirely.

Because of ??, an explicit false in videoSettings correctly shadows the org-level true. If that operator were ever changed to ||, this test suite would still pass — making it possible to silently invert the intended "video setting wins" precedence. Consider adding a case where a space array is empty (or excludes a key), videoSettings.someKey = false, and organizationSettings.someKey = true, and asserting that the result is false.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/web-backend/src/Videos/EffectiveVideoRules.test.ts
Line: 8-42

Comment:
**Precedence between `videoSettings` and `organizationSettings` not covered**

The test name promises to exercise "space settings override video and organization defaults," but the branch where `videoSettings` explicitly sets a flag to `false` while `organizationSettings` sets the same flag to `true` (with no space override) is never reached. For `disableCaptions`, the space provides an override so the `videoSettings?.[key] ?? organizationSettings?.[key]` line is bypassed entirely.

Because of `??`, an explicit `false` in `videoSettings` correctly shadows the org-level `true`. If that operator were ever changed to `||`, this test suite would still pass — making it possible to silently invert the intended "video setting wins" precedence. Consider adding a case where a space array is empty (or excludes a key), `videoSettings.someKey = false`, and `organizationSettings.someKey = true`, and asserting that the result is `false`.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +61 to +75
describe("collectPasswordHashes", () => {
it("keeps the video password first and removes empty space passwords", () => {
expect(
collectPasswordHashes({
videoPassword: "video-hash",
spacePasswords: [
{ password: "space-hash" },
{ password: "" },
{ password: null },
{},
],
}),
).toEqual(["video-hash", "space-hash"]);
});
});
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.

P2 No test for absent / null videoPassword

Only the "happy path" (a truthy videoPassword) is covered. The function also handles videoPassword being undefined or null via ...(videoPassword ? [videoPassword] : []). Adding a test case where videoPassword is omitted or null would confirm the guard works, especially if the function signature changes in the future.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/web-backend/src/Videos/EffectiveVideoRules.test.ts
Line: 61-75

Comment:
**No test for absent / null `videoPassword`**

Only the "happy path" (a truthy `videoPassword`) is covered. The function also handles `videoPassword` being `undefined` or `null` via `...(videoPassword ? [videoPassword] : [])`. Adding a test case where `videoPassword` is omitted or `null` would confirm the guard works, especially if the function signature changes in the future.

How can I resolve this? If you propose a fix, please make it concise.

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

Labels

🙋 Bounty claim contributor:verified Contributor passed trust analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants