Skip to content

test: cover ContextBuilder tenant-scoped prompt-context assembly - #38

Merged
akash4550 merged 1 commit into
mainfrom
feat/context-builder-tests
Aug 10, 2026
Merged

test: cover ContextBuilder tenant-scoped prompt-context assembly#38
akash4550 merged 1 commit into
mainfrom
feat/context-builder-tests

Conversation

@akash4550

Copy link
Copy Markdown
Owner

Problem

ContextBuilder assembles 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 + deletedAt filters 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 as Unassigned; renders Description: 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

  • API tests: 57 suites, 392 passed (384 pre-existing + 8 new)
  • Web tests: 29 files, 147 passed
  • npm run typecheck: clean
  • npm run build: clean
  • Diff: 1 file, 138 additions / 0 deletions; zero new dependencies; zero migrations; zero UI/deployment/CI changes; zero production code changed

Risk

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.

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.
@netlify

netlify Bot commented Aug 10, 2026

Copy link
Copy Markdown

Deploy Preview for teamsynch-ai canceled.

Name Link
🔨 Latest commit 2d19dce
🔍 Latest deploy log https://app.netlify.com/projects/teamsynch-ai/deploys/6a7a21374ae92e0008bf4c30

@akash4550
akash4550 merged commit b1ce236 into main Aug 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant