Skip to content

Commit e12a7df

Browse files
fix(archives): restore get_result error logs + accept @graph shape in E2E test
Two test-driven fixes after running the full local test suite: 1. archives-plugin.unit.php expected the regex pattern `function fetchArchivalUnitsForAuthority(...) ... get_result() ... [Archives] fetchArchivalUnitsForAuthority get_result failed:` — i.e. an explicit error log on get_result failure. A prior fix batch had simplified the code to silently degrade. Restore the explicit `if (!(\$result instanceof \\mysqli_result)) { SecureLogger::error(...); }` branch on BOTH fetchArchivalUnitsForAuthority and fetchAuthoritiesForArchivalUnit so the test's regex matches and the public error contract (logged failure on get_result error) holds. 2. tests/archives-ric-jsonld.spec.js: 'unit ric.json @type' and 'agent ric.json @type' assertions failed when relations exist on the entity (the response shape is now `{@context, @graph: [...]}` after F006 wired fetchRelationsForEntity into the ric handlers). Updated both tests to extract the entity node from `@graph` when present, falling back to flat `body` when not. Both shapes are valid post- F006 — the test just needed to accept the wrapped form. Result: unit tests 60/60, archives ric-jsonld E2E 41/41.
1 parent b70bdd1 commit e12a7df

2 files changed

Lines changed: 31 additions & 14 deletions

File tree

storage/plugins/archives/ArchivesPlugin.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,12 +2811,15 @@ private function fetchArchivalUnitsForAuthority(int $authorityId): array
28112811
return $rows;
28122812
}
28132813
$result = $stmt->get_result();
2814-
if ($result instanceof \mysqli_result) {
2815-
while ($row = $result->fetch_assoc()) {
2816-
$rows[] = $row;
2817-
}
2818-
$result->free();
2814+
if (!($result instanceof \mysqli_result)) {
2815+
SecureLogger::error('[Archives] fetchArchivalUnitsForAuthority get_result failed: ' . $this->db->error);
2816+
$stmt->close();
2817+
return $rows;
2818+
}
2819+
while ($row = $result->fetch_assoc()) {
2820+
$rows[] = $row;
28192821
}
2822+
$result->free();
28202823
$stmt->close();
28212824
return $rows;
28222825
}
@@ -2852,12 +2855,15 @@ public function fetchAuthoritiesForArchivalUnit(int $archivalUnitId): array
28522855
return $rows;
28532856
}
28542857
$result = $stmt->get_result();
2855-
if ($result instanceof \mysqli_result) {
2856-
while ($row = $result->fetch_assoc()) {
2857-
$rows[] = $row;
2858-
}
2859-
$result->free();
2858+
if (!($result instanceof \mysqli_result)) {
2859+
SecureLogger::error('[Archives] fetchAuthoritiesForArchivalUnit get_result failed: ' . $this->db->error);
2860+
$stmt->close();
2861+
return $rows;
2862+
}
2863+
while ($row = $result->fetch_assoc()) {
2864+
$rows[] = $row;
28602865
}
2866+
$result->free();
28612867
$stmt->close();
28622868
return $rows;
28632869
}

tests/archives-ric-jsonld.spec.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,28 @@ test.describe.serial('RiC-O JSON-LD endpoints — v0.7.7', () => {
130130
test.skip(!hasArchives, 'No archival_units seeded');
131131
const res = await request.get(`${BASE}/archives/${unitId}/ric.json`);
132132
const body = await res.json();
133-
expect(body['@type']).toMatch(/^ric:(Record|RecordSet)$/);
134-
expect(body['@id']).toMatch(/\/archives\/\d+$/);
133+
// Post-F006: @graph wrapper when relations exist. Accept both shapes.
134+
const unitNode = Array.isArray(body['@graph'])
135+
? body['@graph'].find(n => /\/archives\/\d+$/.test(n['@id'] ?? ''))
136+
: body;
137+
expect(unitNode, 'unit node present (flat or in @graph)').toBeDefined();
138+
expect(unitNode['@type']).toMatch(/^ric:(Record|RecordSet)$/);
139+
expect(unitNode['@id']).toMatch(/\/archives\/\d+$/);
135140
});
136141

137142
test('GET /archives/agents/{id}/ric.json responds 200 with an agent type', async ({ request }) => {
138143
test.skip(agentId === 0, 'No authority_records seeded');
139144
const res = await request.get(`${BASE}/archives/agents/${agentId}/ric.json`);
140145
expect(res.status()).toBe(200);
141146
const body = await res.json();
142-
expect(body['@type']).toMatch(/^ric:(Person|CorporateBody|Family)$/);
143-
expect(body['@id']).toMatch(/\/archives\/agents\/\d+$/);
147+
// Post-F006: when polymorphic relations exist for the agent the document
148+
// is wrapped in @graph, otherwise it stays flat. Both shapes are valid.
149+
const agentNode = Array.isArray(body['@graph'])
150+
? body['@graph'].find(n => /\/archives\/agents\/\d+$/.test(n['@id'] ?? ''))
151+
: body;
152+
expect(agentNode, 'agent node must be present (flat or in @graph)').toBeDefined();
153+
expect(agentNode['@type']).toMatch(/^ric:(Person|CorporateBody|Family)$/);
154+
expect(agentNode['@id']).toMatch(/\/archives\/agents\/\d+$/);
144155
});
145156

146157
// ── 2. Headers — Cache-Control, Link rel=canonical, CORS, no Vary ─

0 commit comments

Comments
 (0)