@@ -27,7 +27,7 @@ jest.mock('../src/core/snapshot.js', () => ({
2727} ) ) ;
2828
2929import { savePage , saveHtml } from '../src/core/savePageCore.js' ;
30- import { SAVE_TOKEN_ATTRS , HOST_TOKEN_ATTRS } from '../src/utilities/root-attrs.js' ;
30+ import { SAVE_TOKEN_ATTRS , HOST_TOKEN_ATTRS , HOST_IDENTITY_ATTRS , isTabLocalRootAttr } from '../src/utilities/root-attrs.js' ;
3131
3232const pathOf = ( url ) => new URL ( url , 'http://localhost' ) . pathname ;
3333
@@ -150,18 +150,35 @@ describe('save credentials follow the endpoint', () => {
150150} ) ;
151151
152152describe ( 'the token list holds nothing but tokens' , ( ) => {
153- // This is the mistake clayjs made and is still carrying: its one list serves both
154- // the token-resolution job and the morph-protection job, so `htmlclayid` was
155- // appended for the second and silently became a credential for the first. Any
156- // name in SAVE_TOKEN_ATTRS is returned by saveToken() and put straight into the
157- // save URL, so a durable per-file identity in here would be posted as if it were
158- // a credential. Keep the guard structural rather than a comment: clayjs has the
159- // comment.
153+ // Any name in SAVE_TOKEN_ATTRS is returned by saveToken() and put straight into
154+ // the save URL, so a durable per-file identity in here would be posted as if it
155+ // were a credential. clayjs hit exactly that: one list served both the
156+ // token-resolution job and the morph-protection job, `htmlclayid` was appended
157+ // for the second, and it silently became a credential for the first. Both
158+ // libraries now keep two lists. Keep the guard structural rather than a comment.
160159 test ( 'SAVE_TOKEN_ATTRS carries no durable identity attribute' , ( ) => {
161160 expect ( SAVE_TOKEN_ATTRS ) . not . toContain ( 'htmlclayid' ) ;
162161 expect ( SAVE_TOKEN_ATTRS ) . not . toContain ( 'documentid' ) ;
163162 } ) ;
164163
164+ // The identity still needs the morph protection, under both spellings. htmlclay
165+ // serves `documentid` and reads either, and every file saved before that rename
166+ // holds `htmlclayid` on disk forever, so a list that knows one name leaves the
167+ // other unprotected: an incoming frame strips this tab's copy.
168+ test ( 'both identity spellings are protected from a peer morph' , ( ) => {
169+ for ( const name of [ 'documentid' , 'htmlclayid' ] ) {
170+ expect ( HOST_IDENTITY_ATTRS ) . toContain ( name ) ;
171+ expect ( HOST_TOKEN_ATTRS ) . toContain ( name ) ;
172+ expect ( isTabLocalRootAttr ( name , document . documentElement ) ) . toBe ( true ) ;
173+ }
174+ } ) ;
175+
176+ // The order is the contract for any reader taking the first name it finds: a
177+ // document carrying both must resolve to the current one.
178+ test ( 'the current identity spelling is read first' , ( ) => {
179+ expect ( HOST_IDENTITY_ATTRS [ 0 ] ) . toBe ( 'documentid' ) ;
180+ } ) ;
181+
165182 test ( 'a durable identity in the DOM is never mistaken for a token' , async ( ) => {
166183 document . documentElement . setAttribute ( 'htmlclayid' , 'DURABLE-UUID' ) ;
167184
0 commit comments