Files
anonymous_github/test/streamer-failure-evidence.test.js
T
Thomas DurieuxandClaude Opus 5.5 c73e992b7c feat: store the repository picker list and update it by webhook
The anonymize page's "Your repositories" picker now pages and searches a
per-user list stored in MongoDB instead of calling GitHub on every page and
search. GitHub is read only when the list is empty, when the user presses
the new refresh button, or after an installation change marks it stale.

- One sync per list (Mongo lock with a renewed lease); full pagination in
  the background after the first page is returned; rate limits pause syncs.
- GitHub App installation, installation_repositories and repository
  webhooks update the stored lists idempotently. The App must subscribe to
  the Repository event (documented in docs/github-app-setup.md).
- Legacy OAuth lists change only on refresh.
- Picker header shows "Updated 3 min ago" and a refresh button.
- dev-mock: stored list, simulated refresh and webhook endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 08:06:30 +00:00

40 lines
2.7 KiB
JavaScript

const {expect}=require('chai');
const express=require('express');
const http=require('node:http');
const {setTimeout}=require('node:timers');
const {Readable}=require('node:stream');
require('ts-node/register/transpile-only');
const {monitorRequests,RequestMetrics}=require('../src/core/request-monitoring');
const GitHubStream=require('../src/core/source/GitHubStream').default;
const {AnonymizeTransformer}=require('../src/core/anonymize-utils');
const streamer=require('../src/streamer/route').default;
const config=require('../src/config').default;
describe('streamer failure provenance',()=>{
for(const mode of ['cache','transform']) it(`records ${mode} failures before teardown without inventing upstream provenance`,async()=>{
const originalCache=GitHubStream.prototype.getFileContentCache,originalTransform=AnonymizeTransformer.prototype._transform,shared=config.SHARED_CACHE_ENABLED;
const logs=[];let server;
try{
config.SHARED_CACHE_ENABLED=false;
GitHubStream.prototype.getFileContentCache=async()=>{
const input=new Readable({read(){}});
setTimeout(()=>input.push(Buffer.from('partial')),10);
if(mode==='cache')setTimeout(()=>input.destroy(Object.assign(new Error('PRIVATE cache path'),{code:'EIO'})),30);
else setTimeout(()=>input.push(Buffer.from('fail')),30);
return input;
};
AnonymizeTransformer.prototype._transform=function(chunk,_encoding,done){
if(mode==='transform'&&chunk.toString()==='fail')done(new Error('PRIVATE output spool'));
else {this.push(chunk);done();}
};
const app=express();app.use(monitorRequests('streamer',new RequestMetrics(),{info:(_,r)=>logs.push(r),warn:(_,r)=>logs.push(r)}));app.use(express.json());app.use('/api',streamer);
server=await new Promise(resolve=>{const s=app.listen(0,'127.0.0.1',()=>resolve(s));});
await new Promise(resolve=>{
const req=http.request({host:'127.0.0.1',port:server.address().port,path:'/api',method:'POST',headers:{'content-type':'application/json'}},res=>{res.resume();res.on('close',resolve);});
req.on('error',resolve);req.end(JSON.stringify({token:'',repoFullName:'PRIVATE/repo',repoId:'demo',filePath:'file.txt',anonymizerOptions:{terms:[],filePath:'file.txt'}}));
});
await new Promise(resolve=>setTimeout(resolve,20));
expect(logs).length(1);expect(logs[0]).include({status:200,outcome:'interrupted',cancellationOrigin:mode==='transform'?'streamer':'unknown',cancellationEvidence:'local_abort',bytes:7});
}finally{GitHubStream.prototype.getFileContentCache=originalCache;AnonymizeTransformer.prototype._transform=originalTransform;config.SHARED_CACHE_ENABLED=shared;if(server){server.closeAllConnections();await new Promise(resolve=>server.close(resolve));}}
});
});