test: cover ContextBuilder tenant-scoped prompt-context assembly - #38
Merged
Conversation
ContextBuilder feeds task/project context into AI prompts and is security-sensitive (cross-tenant leaks would reach the LLM), yet had zero coverage. New deterministic tests (mocked prisma): - buildTaskContext: 400 on missing org (fails before any query); tenant-scoped query asserted (organizationId + deletedAt on task, project, and the subtasks select); 404 on missing/cross-tenant task; inactive/deleted assignee renders as Unassigned; Description: None - buildProjectContext: 400 on missing org; tenant-scoped query asserted (project + tasks select); task summary formatting; 404 on missing/cross-tenant project; friendly empty-task message No production code changed.
✅ Deploy Preview for teamsynch-ai canceled.
|
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.
Problem
ContextBuilderassembles the task/project context that goes into AI prompts — and it is security-sensitive: a cross-tenant leak here would reach the LLM directly. It had zero unit coverage; its tenant-scoping, fail-closed guards, and 404 behavior were unpinned.Solution
A new deterministic test suite (
context.builder.test.ts) with mocked prisma — no DB, no network:buildTaskContext: throws 400 on missing org (before any query); asserts the tenant-scoped query (organizationId+deletedAtfilters on the task, its project, and the subtasks select — cross-tenant rows can never match); throws 404 on a missing/cross-tenant task; renders an inactive/deleted assignee asUnassigned; rendersDescription: None.buildProjectContext: throws 400 on missing org; asserts the tenant-scoped query (project + tasks select); formats the[PROJECT CONTEXT]task summary; throws 404 on a missing/cross-tenant project; renders the friendly empty-task message.Validation results
npm run typecheck: cleannpm run build: cleanRisk
LOW. Tests only — no production code touched.
Rollback
Revert the PR (delete the test file). No production impact either way.
Production behavior
Not changed. Prompt-context assembly, tenant filtering, and all AI behavior are untouched. Only coverage was added.