feat(cognigate): live trust_service + real tests for n8n node#98
Merged
feat(cognigate): live trust_service + real tests for n8n node#98
Conversation
6 tasks
c8a8f09 to
06c6a0e
Compare
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>
06c6a0e to
62c5dd5
Compare
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.
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.
Regression guards added to tests/test_intent.py:
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:
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
Test plan