feat(iace): wire crossref into tech-file, library UI, and contract tests

Three follow-ups to the 671-norm cross-reference matrix:

1. Tech-file renderer (Go): standards_applied section now gets a deterministic
   Markdown appendix with the DIN/ANSI/GB/JIS mappings for the project's
   suggested norms. Built from registry, never hallucinated by LLM. Applied
   both to LLM and fallback content paths.

2. Frontend NormCrossRefPanel (Next.js): expandable row in the IACE library
   norms tab now has a "Internationale Aequivalenzen anzeigen" button that
   lazy-loads /iace/norms-library/:id/crossref and renders a colour-coded
   table (relation + confidence). Region labels humanised (US — ANSI,
   China (GB), Japan (JIS), etc.).

3. Contract tests (Go): 4 new handler tests pinning the response shape of
   GetNormCrossRef and ListNormCrossRefs. Equivalent to an OpenAPI snapshot
   for these specific endpoints — ai-compliance-sdk has no full OpenAPI
   baseline yet (separate ticket).

Tests: 6 renderer tests + 4 handler contract tests, all green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-05-22 09:48:07 +02:00
parent cf6005a47c
commit 0a84c747f2
6 changed files with 587 additions and 2 deletions
@@ -0,0 +1,110 @@
package handlers
import (
"encoding/json"
"testing"
"github.com/gin-gonic/gin"
)
// Contract tests for the new /norms-library/crossref endpoints.
// These are the practical equivalent of an OpenAPI snapshot: they pin
// the response shape so a downstream consumer (admin-compliance,
// developer-portal, SDK) cannot be silently broken.
func TestGetNormCrossRef_KnownID_ReturnsExpectedShape(t *testing.T) {
handler := &IACEHandler{}
w, c := newTestContext("GET", "/norms-library/ISO-12100/crossref", nil, nil, gin.Params{
{Key: "id", Value: "ISO-12100"},
})
handler.GetNormCrossRef(c)
if w.Code != 200 {
t.Fatalf("expected 200, got %d body=%s", w.Code, w.Body.String())
}
var resp struct {
NormID string `json:"norm_id"`
Mappings []struct {
Region string `json:"region"`
Identifier string `json:"identifier"`
Relation string `json:"relation"`
Confidence string `json:"confidence"`
} `json:"mappings"`
BatchID string `json:"batch_id"`
}
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("response not parsable: %v body=%s", err, w.Body.String())
}
if resp.NormID != "ISO-12100" {
t.Errorf("expected norm_id ISO-12100, got %q", resp.NormID)
}
if len(resp.Mappings) < 3 {
t.Errorf("expected ISO-12100 to have at least 3 mappings, got %d", len(resp.Mappings))
}
}
func TestGetNormCrossRef_MissingID_Returns400(t *testing.T) {
handler := &IACEHandler{}
w, c := newTestContext("GET", "/norms-library//crossref", nil, nil, gin.Params{
{Key: "id", Value: ""},
})
handler.GetNormCrossRef(c)
if w.Code != 400 {
t.Errorf("expected 400 for missing id, got %d", w.Code)
}
}
func TestGetNormCrossRef_UnknownID_ReturnsEmptyMappings(t *testing.T) {
handler := &IACEHandler{}
w, c := newTestContext("GET", "/norms-library/ISO-DOESNOTEXIST/crossref", nil, nil, gin.Params{
{Key: "id", Value: "ISO-DOESNOTEXIST"},
})
handler.GetNormCrossRef(c)
if w.Code != 200 {
t.Fatalf("expected 200 for unknown id (returns empty), got %d", w.Code)
}
var resp struct {
NormID string `json:"norm_id"`
Mappings []interface{} `json:"mappings"`
}
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("response not parsable: %v", err)
}
if resp.NormID != "ISO-DOESNOTEXIST" {
t.Errorf("expected norm_id to echo back, got %q", resp.NormID)
}
if len(resp.Mappings) != 0 {
t.Errorf("expected empty mappings, got %d", len(resp.Mappings))
}
}
func TestListNormCrossRefs_ReturnsAll(t *testing.T) {
handler := &IACEHandler{}
w, c := newTestContext("GET", "/norms-library/crossref", nil, nil, nil)
handler.ListNormCrossRefs(c)
if w.Code != 200 {
t.Fatalf("expected 200, got %d", w.Code)
}
var resp struct {
Entries []struct {
NormID string `json:"norm_id"`
} `json:"entries"`
Total int `json:"total"`
}
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("response not parsable: %v", err)
}
if resp.Total != 671 {
t.Errorf("expected 671 cross-ref entries, got %d", resp.Total)
}
if len(resp.Entries) != resp.Total {
t.Errorf("entries count %d does not match total %d", len(resp.Entries), resp.Total)
}
}