Skip to content

Commit 1296e8d

Browse files
[Agent: Claude] fix(lws): JSON-LD conversion arm gets a variant ETag; prediction keyed on the real negotiation surface (review JavaScriptSolidServer#5)
- predictFileEtag now runs its RDF branch unconditionally (was gated on connegEnabled while the serving arm runs under connegEnabled||lwsEnabled) - the JSON-LD conversion of a non-JSON-LD RDF source (e.g. a .ttl resource read with Accept: application/ld+json) now gets a '-json' variant ETag — previously it shared the bare stats ETag with the Turtle bytes, enabling cross-variant 304 reuse (RFC 9110 §8.8.3 / LWS ETag MUST violation) - own-format reads and existing quads-variant keys are unchanged (all prior pins in test/lws-etag-variant.test.js stay green) - extends test/lws-etag-variant.test.js with 5 new cases proving: -json suffix on conversion, bare ETag + divergence on own-format, no cross-variant 304, same-variant 304 still works, and HEAD/GET ETag parity on both arms Co-Authored-By: Claude Opus 4.8 <[email protected]>
1 parent f0e3c4d commit 1296e8d

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

‎src/handlers/resource.js‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,21 @@ function predictFileEtag(request, stats, effectiveEtag, willServeMashlib, storag
247247
return variantEtag(stats.etag, 'ls');
248248
}
249249
const storedContentType = getContentType(storagePath);
250-
if (connegEnabled && isRdfSourceType(storedContentType)) {
251-
const quadsTarget = negotiateQuadsTarget(acceptHeader, connegEnabled, true, urlPath);
250+
// #5 (RFC 9110 §8.8.3 / LWS ETag MUST): keyed on the negotiation surface the
251+
// serving arm actually runs (this function already early-returns unless
252+
// lwsEnabled, and --lws mandates negotiation — spec §4a), and covering BOTH
253+
// conversion arms: quads targets get their VARIANT_KEYS suffix, the JSON-LD
254+
// conversion of a non-JSON-LD source gets '-json'. Before this, Turtle
255+
// bytes and their JSON-LD conversion shared one bare ETag (cross-variant
256+
// 304 reuse), and --lws-without---conneg collapsed every variant.
257+
if (isRdfSourceType(storedContentType)) {
258+
const quadsTarget = negotiateQuadsTarget(acceptHeader, true, true, urlPath);
252259
if (quadsTarget && quadsTarget !== storedContentType) {
253260
return variantEtag(stats.etag, VARIANT_KEYS[quadsTarget]);
254261
}
262+
if (!quadsTarget && storedContentType !== RDF_TYPES.JSON_LD) {
263+
return variantEtag(stats.etag, 'json'); // the ld+json conversion arm (~line 1097)
264+
}
255265
}
256266
return stats.etag;
257267
}

‎test/lws-etag-variant.test.js‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,48 @@ describe('negative control: --lws off, ETags stay bare and byte-identical across
191191
assert.equal(ttl.headers.get('etag'), etag);
192192
});
193193
});
194+
195+
describe('lws: JSON-LD conversion arm ETag (review #5)', () => {
196+
let base;
197+
const TTL = '/etagj/public/r.ttl';
198+
before(async () => {
199+
await startTestServer({ lws: true, conneg: true });
200+
base = getBaseUrl();
201+
await createTestPod('etagj');
202+
await request(TTL, { method: 'PUT', headers: { 'Content-Type': 'text/turtle' }, auth: 'etagj',
203+
body: '<#s> <http://ex/p> "v".' });
204+
});
205+
after(stopTestServer);
206+
207+
it('the JSON-LD conversion of a .ttl source carries a -json variant ETag', async () => {
208+
const r = await request(TTL, { headers: { Accept: 'application/ld+json' } });
209+
assertStatus(r, 200);
210+
assert.match(r.headers.get('etag'), /-json"$/);
211+
});
212+
213+
it('own-format .ttl GET keeps the bare ETag; the two variants differ', async () => {
214+
const ttl = await request(TTL, { headers: { Accept: 'text/turtle' } });
215+
const json = await request(TTL, { headers: { Accept: 'application/ld+json' } });
216+
assert.match(ttl.headers.get('etag'), BARE_ETAG_RE);
217+
assert.notEqual(ttl.headers.get('etag'), json.headers.get('etag'));
218+
});
219+
220+
it('a Turtle-variant If-None-Match never 304s the JSON-LD variant (cross-variant)', async () => {
221+
const ttl = await request(TTL, { headers: { Accept: 'text/turtle' } });
222+
const r = await request(TTL, { headers: { Accept: 'application/ld+json', 'If-None-Match': ttl.headers.get('etag') } });
223+
assertStatus(r, 200);
224+
});
225+
226+
it('same-variant If-None-Match still 304s', async () => {
227+
const json = await request(TTL, { headers: { Accept: 'application/ld+json' } });
228+
const r = await request(TTL, { headers: { Accept: 'application/ld+json', 'If-None-Match': json.headers.get('etag') } });
229+
assertStatus(r, 304);
230+
assert.match(r.headers.get('etag'), /-json"$/);
231+
});
232+
233+
it('HEAD mirrors GET ETags on both arms', async () => {
234+
const g = await request(TTL, { headers: { Accept: 'application/ld+json' } });
235+
const h = await request(TTL, { method: 'HEAD', headers: { Accept: 'application/ld+json' } });
236+
assert.equal(h.headers.get('etag'), g.headers.get('etag'));
237+
});
238+
});

0 commit comments

Comments
 (0)