fix(core): don't persist browser consent sentinel in non-interactive mode (#23073)

This commit is contained in:
Jason Matthew Suhari
2026-03-19 14:47:13 +08:00
committed by GitHub
parent e9171fd792
commit a921bcd9ef
2 changed files with 8 additions and 8 deletions

View File

@@ -47,7 +47,7 @@ describe('browserConsent', () => {
expect(emitSpy).not.toHaveBeenCalled();
});
it('should auto-accept in non-interactive mode (no listeners)', async () => {
it('should auto-accept in non-interactive mode (no listeners) without persisting consent', async () => {
// Consent file does not exist
vi.mocked(fs.access).mockRejectedValue(new Error('ENOENT'));
// No listeners registered
@@ -56,11 +56,9 @@ describe('browserConsent', () => {
const result = await getBrowserConsentIfNeeded();
expect(result).toBe(true);
// Should persist the consent
expect(fs.writeFile).toHaveBeenCalledWith(
expect.stringContaining('browser-consent-acknowledged.txt'),
expect.stringContaining('consent acknowledged'),
);
// Should NOT persist the consent — an interactive user on the same machine
// must still see the dialog the first time they use the browser agent.
expect(fs.writeFile).not.toHaveBeenCalled();
});
it('should request consent interactively and return true when accepted', async () => {

View File

@@ -42,9 +42,11 @@ export async function getBrowserConsentIfNeeded(): Promise<boolean> {
void 0;
}
// Non-interactive mode (no UI listeners): auto-accept.
// Non-interactive mode (no UI listeners): skip the dialog for this session
// only. Do NOT persist the sentinel file — an interactive user on the same
// machine should still see the consent dialog the first time they use the
// browser agent.
if (coreEvents.listenerCount(CoreEvent.ConsentRequest) === 0) {
await markConsentAsAcknowledged(consentFilePath);
return true;
}