Guard stale app execution against feature contract changes

This commit is contained in:
Jonathan Sykes
2026-10-08 09:18:51 +08:00
parent 3505dc3c0e
commit c4a512bea6
7 changed files with 143 additions and 8 deletions

View File

@@ -42,7 +42,8 @@
const previousKey=state && root.AssetSyncCore.fallback(manifest,state.previous,'/app.js');
const previous=previousKey && await cache.match(previousKey);
const previousHash=state?.previous?.files['/app.js']?.h;
if(root.navigator?.serviceWorker?.controller && previous?.ok && previous.headers.get('X-Asset-Hash')===previousHash) {
const contractsMatch=state?.previous && Object.entries(manifest.groups).every(([name,group])=>state.previous.groups[name]?.contract===group.contract);
if(contractsMatch && root.navigator?.serviceWorker?.controller && previous?.ok && previous.headers.get('X-Asset-Hash')===previousHash) {
await verified(previous,previousHash);
delete root.Lazy.appResponse;
return external(previousKey);

View File

@@ -54,3 +54,10 @@ test('missing current app uses verified same-contract N-1 offline through the co
test('an incompatible previous core never executes against the new shell',async()=>{
const f=fixture({previous:true,contract:2});await assert.rejects(f.root.AppBootstrap.ready,/hash/);assert.equal(f.root.appRuns,undefined);
});
test('a feature contract change also prevents stale core execution',async()=>{
const f=fixture({previous:true});f.root.Lazy.manifest.groups['feature:test']={contract:2,files:[]};
const state=await f.held.get('/__ytp_asset_state').json();state.previous.groups['feature:test']={contract:1,files:[]};f.held.set('/__ytp_asset_state',Response.json(state));
await assert.rejects(f.root.AppBootstrap.ready,/hash/);assert.equal(f.root.appRuns,undefined);
});