Skip to content

Commit d87612b

Browse files
Address PR #86 review: tighten coverage gates and test hygiene
Raise vitest thresholds to lines 80 / functions 70 / branches 50 so the ~85% gain is actually protected. Stub URL blob methods without replacing the constructor, restore navigator.clipboard after copyAll tests, assert new_string HTML escaping in edit.test.js, and document that CI test:coverage runs the full vitest suite.
1 parent 8b02a9d commit d87612b

5 files changed

Lines changed: 38 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ jobs:
203203
*) echo "Unsupported Node platform: $(node -p "process.platform + '-' + process.arch")"; exit 1 ;;
204204
esac
205205
npm install --no-save "${PKG}@${ROLLUP_VERSION}"
206+
# Same vitest suite as npm test; --coverage enforces thresholds in vitest.config.js
206207
- run: npm run test:coverage
207208

208209
benchmarks:

static/js/export.test.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ describe('export', () => {
112112
vi.stubGlobal('showSaveFilePicker', undefined);
113113
const createObjectURL = vi.fn(() => 'blob:fake-url');
114114
const revokeObjectURL = vi.fn();
115-
vi.stubGlobal('URL', { createObjectURL, revokeObjectURL });
115+
const origCreate = URL.createObjectURL;
116+
const origRevoke = URL.revokeObjectURL;
117+
URL.createObjectURL = createObjectURL;
118+
URL.revokeObjectURL = revokeObjectURL;
116119
const click = vi.fn();
117120
const anchor = document.createElement('a');
118121
anchor.click = click;
@@ -127,10 +130,17 @@ describe('export', () => {
127130
blob: () => Promise.resolve(new Blob(['content'], { type: 'text/markdown' })),
128131
});
129132

130-
await downloadSession('alpha', 'sess-abcdef12');
131-
132-
expect(createObjectURL).toHaveBeenCalled();
133-
expect(anchor.download).toBe('session-sess-abc.md');
134-
expect(click).toHaveBeenCalled();
133+
try {
134+
await downloadSession('alpha', 'sess-abcdef12');
135+
136+
expect(createObjectURL).toHaveBeenCalled();
137+
expect(anchor.download).toBe('session-sess-abc.md');
138+
expect(click).toHaveBeenCalled();
139+
} finally {
140+
if (origCreate) URL.createObjectURL = origCreate;
141+
else delete URL.createObjectURL;
142+
if (origRevoke) URL.revokeObjectURL = origRevoke;
143+
else delete URL.revokeObjectURL;
144+
}
135145
});
136146
});

static/js/render/tool_use/edit.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ describe('renderEditUse', () => {
2828
});
2929
expect(html).not.toContain('<bad>');
3030
expect(html).toContain('&lt;bad&gt;');
31+
expect(html).not.toContain('<worse>');
32+
expect(html).toContain('&lt;worse&gt;');
3133
});
3234
});

static/js/sessions.test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ function mockWorkspaceFetch() {
7878
}
7979

8080
describe('sessions workspace', () => {
81+
let clipboardRestore;
82+
8183
beforeEach(() => {
8284
document.body.innerHTML = '<div id="content"></div>';
8385
state.currentProject = null;
@@ -88,6 +90,14 @@ describe('sessions workspace', () => {
8890
});
8991

9092
afterEach(() => {
93+
if (clipboardRestore) {
94+
Object.defineProperty(navigator, 'clipboard', {
95+
value: clipboardRestore,
96+
configurable: true,
97+
writable: true,
98+
});
99+
clipboardRestore = null;
100+
}
91101
vi.unstubAllGlobals();
92102
});
93103

@@ -146,7 +156,12 @@ describe('sessions workspace', () => {
146156

147157
it('copyAll writes session text to the clipboard', async () => {
148158
const writeText = vi.fn(() => Promise.resolve());
149-
Object.assign(navigator, { clipboard: { writeText } });
159+
clipboardRestore = navigator.clipboard;
160+
Object.defineProperty(navigator, 'clipboard', {
161+
value: { writeText },
162+
configurable: true,
163+
writable: true,
164+
});
150165
const el = document.createElement('div');
151166
el.className = 'session-content-inner';
152167
el.textContent = 'Line one\nLine two';

vitest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export default defineConfig({
1010
include: ['static/js/**/*.js'],
1111
exclude: ['static/js/**/*.test.js'],
1212
thresholds: {
13-
lines: 50,
13+
lines: 80,
14+
functions: 70,
15+
branches: 50,
1416
},
1517
},
1618
},

0 commit comments

Comments
 (0)