Skip to content

feat(cognigate): live trust_service + real tests for n8n node#98

Merged
vorionsys merged 1 commit intomainfrom
fix/cognigate-live-trust-and-tests
Apr 11, 2026
Merged

feat(cognigate): live trust_service + real tests for n8n node#98
vorionsys merged 1 commit intomainfrom
fix/cognigate-live-trust-and-tests

Conversation

@vorionsys
Copy link
Copy Markdown
Owner

Summary

Two production-quality gaps in cognigate inside the monorepo — closed together because they're related and both belong to the "make things live, not stubs" directive.

1. cognigate-api/app/routers/intent.py — kill `MOCK_TRUST_SCORES`

`intent.py` was shipping a hardcoded 3-entity `MOCK_TRUST_SCORES` dict with a "replace with real service" comment. Every other router (`admin.py`, `enforce.py`) was already routing through the real `trust_service` singleton — intent.py was the outlier.

  • Remove the dict entirely and route through `trust_service.get_trust_async()`, which gets the AgentAnchor remote provider for free when wired.
  • Relabel two other `(mock)` comments in `analyze_intent` — the data-classification and endpoint-extraction blocks are real heuristic scans, not stubs. The comment was misleading.
  • Remove unused `TrustLevel` import.

Regression guards added to tests/test_intent.py:

  • `test_trust_routed_through_trust_service` — seeds a fresh entity directly on the service and confirms the endpoint surfaces it (proves no local dict is shadowing the real service)
  • `test_seeded_agent_001_score` — confirms the seeded defaults from `trust_service` continue to give the same observable values the old MOCK dict did, so nothing downstream sees a behavior change

Test result: cognigate-api full suite 147 passed (was 145).

2. packages/n8n-nodes-cognigate — zero tests → 46 tests

The 870-line n8n community node had jest configured with `--passWithNoTests` and an empty `tests/` directory. Added tests/Cognigate.node.test.ts covering:

  • cognigateRequest helper: baseUrl trailing-slash stripping, `X-API-Key` header, `X-Admin-Key` gated on `useAdminKey=true` (compliance/trigger path), `NodeApiError` wrapping on HTTP failures
  • All 8 resources (`intent`, `enforce`, `proof`, `agent`, `trust`, `health`, `reference`, `compliance`) × every operation dispatch branch — verifies method, URL, body, querystring
  • execute()-level error paths: unknown resource throws, `continueOnFail` captures error per item instead of propagating
  • Output normalization: single-object wrap, array expansion

Tests use a synthetic `IExecuteFunctions` context that captures the `httpRequest` call — no live HTTP, no n8n runtime dependency.

Also replaces `"test:local": "jest --passWithNoTests"` with a real `"test": "jest"` script so `npx turbo test` picks the package up.

Test result: jest 46 passed (was 0).

Impact

  • `intent.py` now benefits from live AgentAnchor remote trust lookups when `set_remote_provider()` is wired at startup — previously it ignored whatever provider was set and always read the hardcoded dict.
  • The n8n community node now has meaningful regression coverage before publication.
  • Both test suites run fast (<3s combined) so there's no CI budget impact.

Test plan

  • cognigate-api pytest: `cd cognigate-api && pytest` → 147 passed
  • n8n-nodes-cognigate jest: `cd packages/n8n-nodes-cognigate && npm test` → 46 passed
  • `npx turbo test --filter=@vorionsys/n8n-nodes-cognigate` includes the new tests in the run

@vorionsys vorionsys force-pushed the fix/cognigate-live-trust-and-tests branch 6 times, most recently from c8a8f09 to 06c6a0e Compare April 11, 2026 23:43
Two production-quality gaps in the in-monorepo cognigate code:

1) cognigate-api/app/routers/intent.py — kill MOCK_TRUST_SCORES
   intent.py used to ship a hardcoded 3-entity MOCK_TRUST_SCORES dict
   with a "replace with real service" comment. Every other router
   (admin.py, enforce.py) was already routing through the real
   trust_service singleton — intent.py was the outlier. Remove the
   dict entirely and route through trust_service.get_trust_async(),
   which gets the AgentAnchor remote provider for free when wired.
   Also relabel two other "(mock)" comments in analyze_intent — the
   data-classification and endpoint-extraction blocks are real
   heuristic scans, not stubs. The comment was misleading.

   Adds two regression guards to tests/test_intent.py:
   - test_trust_routed_through_trust_service: seeds a fresh entity
     directly on the service and confirms the endpoint surfaces it
     (proving no local dict is shadowing the real service).
   - test_seeded_agent_001_score: confirms the seeded defaults from
     trust_service continue to give the same observable trust values
     that the old MOCK dict did.

   Full cognigate-api test suite: 147 passed (was 145).

2) packages/n8n-nodes-cognigate — zero tests → 46 tests
   The 870-line n8n community node had jest configured with
   --passWithNoTests and an empty tests/ directory. Added
   tests/Cognigate.node.test.ts covering:
   - cognigateRequest helper: baseUrl slash-stripping, X-API-Key
     header, X-Admin-Key gated on useAdminKey, NodeApiError
     wrapping on HTTP failures
   - all 8 resources (intent, enforce, proof, agent, trust, health,
     reference, compliance) × every operation dispatch branch:
     method, URL, body, querystring
   - execute()-level error paths: unknown resource throws,
     continueOnFail captures error per item instead of propagating
   - output normalization: single-object wrap, array expansion

   Tests use a synthetic IExecuteFunctions context that captures the
   httpRequest call — no live HTTP, no n8n runtime dependency.
   Removes --passWithNoTests from the test:local script and adds a
   proper `npm test` entry so turbo picks it up.

   Jest: 46 passed (was 0).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vorionsys vorionsys force-pushed the fix/cognigate-live-trust-and-tests branch from 06c6a0e to 62c5dd5 Compare April 11, 2026 23:43
@vorionsys vorionsys merged commit 68bb72f into main Apr 11, 2026
45 of 55 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.

2 participants