Skip to content

Commit 0a75c0e

Browse files
Clear reverted CLI watch paths from the stale banner.
When a live fetch matches the analyzed file content, drop that path from cliDirty and cliLiveByPath so an edit-then-revert does not leave a permanent Re-analyze banner. Other dirty files stay marked. Co-authored-by: Braedon Saunders <braedonsaunders@users.noreply.github.com>
1 parent 45355a2 commit 0a75c0e

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5911,6 +5911,26 @@
59115911
return noteCliWatchPath(prev,next);
59125912
}
59135913

5914+
function forgetCliWatchPath(prev,path){
5915+
var next=normalizeCliWatchPath(path);
5916+
if(!next)return prev||[];
5917+
return (prev||[]).filter(function(item){return item!==next;});
5918+
}
5919+
5920+
function analyzedFileForCliWatchPath(files,path){
5921+
var next=normalizeCliWatchPath(path);
5922+
if(!next||!files)return null;
5923+
for(var i=0;i<files.length;i++){
5924+
var file=files[i];
5925+
if(file&&normalizeCliWatchPath(file.path)===next)return file;
5926+
}
5927+
return null;
5928+
}
5929+
5930+
function cliWatchLiveMatchesBaseline(file,liveContent){
5931+
return !!(fileHasAnalyzedSourceForDiff(file)&&typeof liveContent==='string'&&liveContent===file.content);
5932+
}
5933+
59145934
function mergeCliLiveContents(prev,updates){
59155935
var next=Object.assign(Object.create(null),prev||{});
59165936
(updates||[]).forEach(function(update){
@@ -9279,6 +9299,12 @@
92799299
if(!cliWatchDiffRequestIsCurrent(cliDiffEpochRef.current,epoch,cliDiffGenRef.current,path,gen))return;
92809300
if(!shouldApplyCliWatchLive(result))return;
92819301
var live=result.kind==='missing'?'':result.content;
9302+
var file=analyzedFileForCliWatchPath(dataRef.current&&dataRef.current.files,path);
9303+
if(cliWatchLiveMatchesBaseline(file,live)){
9304+
setCliLiveByPath(function(prev){return mergeCliLiveContents(prev,[{path:path,content:null}]);});
9305+
setCliDirty(function(prev){return forgetCliWatchPath(prev,path);});
9306+
return;
9307+
}
92829308
setCliLiveByPath(function(prev){return mergeCliLiveContents(prev,[{path:path,content:live}]);});
92839309
});
92849310
});

tests/code-canvas.test.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,15 @@ test('CLI analysis keeps watch paths received while files were being read', () =
16571657
assert.deepEqual(J(context.noteCliWatchPathIfRead(['src/app.js'], 'src/later.js', { 'src/app.js': true })), ['src/app.js']);
16581658
assert.deepEqual(J(context.noteCliWatchPathIfRead([], 'src/app.js', {})), []);
16591659
assert.deepEqual(J(context.noteCliWatchPathIfRead([], 'src/app.js', null)), []);
1660+
assert.deepEqual(J(context.forgetCliWatchPath(['src/app.js', 'src/math.js'], 'src/app.js')), ['src/math.js']);
1661+
assert.deepEqual(J(context.forgetCliWatchPath(['src/app.js'], 'src/math.js')), ['src/app.js']);
1662+
assert.deepEqual(J(context.forgetCliWatchPath(['src/app.js'], '')), ['src/app.js']);
1663+
const analyzed = [{ path: 'src/app.js', content: 'export const n = 1;\n' }, { path: 'src/math.js', content: 'export const n = 2;\n' }];
1664+
assert.equal(context.analyzedFileForCliWatchPath(analyzed, '/src/app.js').content, 'export const n = 1;\n');
1665+
assert.equal(context.cliWatchLiveMatchesBaseline(analyzed[0], 'export const n = 1;\n'), true);
1666+
assert.equal(context.cliWatchLiveMatchesBaseline(analyzed[0], 'export const n = 2;\n'), false);
1667+
assert.equal(context.cliWatchLiveMatchesBaseline(analyzed[0], ''), false);
1668+
assert.equal(context.cliWatchLiveMatchesBaseline({ path: 'src/app.js', content: 'export const n = 1;\n', analysisSkipped: 'fetch-failed' }, 'export const n = 1;\n'), false);
16601669
assert.deepEqual(J(context.cliWatchLiveFromResponse(200, 'ok\n', true)), { kind: 'ok', content: 'ok\n' });
16611670
assert.deepEqual(J(context.cliWatchLiveFromResponse(404, 'nope', false)), { kind: 'missing', content: '' });
16621671
assert.deepEqual(J(context.cliWatchLiveFromResponse(500, 'err', false)), { kind: 'error' });
@@ -1855,6 +1864,8 @@ test('index.html ships a working Code view, not a stub', () => {
18551864
assert.match(htmlSource, /cliWatchReadRef\.current\[normalizeCliWatchPath\(f\.path\)\]=true/);
18561865
assert.match(htmlSource, /readCliWatchLiveSource\(path\)/);
18571866
assert.match(htmlSource, /if\(!shouldApplyCliWatchLive\(result\)\)return/);
1867+
assert.match(htmlSource, /if\(cliWatchLiveMatchesBaseline\(file,live\)\)/);
1868+
assert.match(htmlSource, /setCliDirty\(function\(prev\)\{return forgetCliWatchPath\(prev,path\);\}/);
18581869
assert.match(htmlSource, /setCliDirty\(keep\)/);
18591870
assert.doesNotMatch(htmlSource, /setCachedFromId\(null\);\s*setCliDirty\(\[\]\);\s*clearCliLiveDiffs\(\);/);
18601871
assert.match(htmlSource, /codeCardSizeForDiff\(file,prefs,rows\)/);

0 commit comments

Comments
 (0)