Skip to content

Commit 9af0da9

Browse files
test(metadata): delete the eight always-true if (manager.X) guards so the assertions actually run (#15401)
Every assertion in `metadata-history.test.ts` sat inside a truthiness guard over the very method under test — `if (manager.getHistory)`, `if (manager.rollback)`, `if (manager.diff)` — at :47 :81 :111 :146 :167 :197 :207 :222, one per `it()`, eight guards over eight tests. All three are UNCONDITIONAL members of `MetadataManager` (`metadata-manager.ts` :3105 `async getHistory(`, :3129 `async rollback(`, :3179 `async diff(`), so each guard is always true and buys nothing — while making every assertion structurally optional. Rename or retire one of the three and the guard goes false, the block is skipped, the `it()` finishes asserting nothing, and the suite reports GREEN. A test that stops testing looked identical to one that passes. Measured rather than argued, by a paired ablation on the METHOD (rename `async diff(` out of `MetadataManager`, mutation confirmed on disk by grep counts of the vanished anchor and an injected marker, restored under a trap and proven against the path's HEAD blob hash plus an empty `git diff HEAD`): with the guards present → vitest GREEN, 8 passed, exit 0 (the silent skip) with the guards deleted → vitest RED (see PR body) Only the guards and their braces are removed; the bodies are de-indented and NO assertion is rewritten — the `patch!` non-null at the old :150 is carried through verbatim. 228 lines to 212, 8 `it()` blocks and 20 `expect(` calls before and after. Claude-Session: https://claude.ai/code/session_01ARYe3yQTQCUFm5qPYNgKaJ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9b9f1aa commit 9af0da9

1 file changed

Lines changed: 37 additions & 53 deletions

File tree

packages/metadata/src/metadata-history.test.ts

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ describe('Metadata History', () => {
4444
await manager.register('object', 'test_object', objectDef);
4545

4646
// Check that history was created
47-
if (manager.getHistory) {
48-
const history = await manager.getHistory('object', 'test_object');
47+
const history = await manager.getHistory('object', 'test_object');
4948

50-
expect(history.records.length).toBeGreaterThan(0);
51-
expect(history.records[0].operationType).toBe('create');
52-
expect(history.records[0].version).toBe(1);
53-
}
49+
expect(history.records.length).toBeGreaterThan(0);
50+
expect(history.records[0].operationType).toBe('create');
51+
expect(history.records[0].version).toBe(1);
5452
});
5553

5654
it('should create history record on metadata update', async () => {
@@ -78,13 +76,11 @@ describe('Metadata History', () => {
7876
await manager.register('object', 'test_object', updatedDef);
7977

8078
// Check history
81-
if (manager.getHistory) {
82-
const history = await manager.getHistory('object', 'test_object');
79+
const history = await manager.getHistory('object', 'test_object');
8380

84-
expect(history.records.length).toBeGreaterThanOrEqual(2);
85-
expect(history.records[0].operationType).toBe('update');
86-
expect(history.records[0].version).toBe(2);
87-
}
81+
expect(history.records.length).toBeGreaterThanOrEqual(2);
82+
expect(history.records[0].operationType).toBe('update');
83+
expect(history.records[0].version).toBe(2);
8884
});
8985

9086
it('should rollback to previous version', async () => {
@@ -108,12 +104,10 @@ describe('Metadata History', () => {
108104
await manager.register('object', 'test_object', version2);
109105

110106
// Rollback to version 1
111-
if (manager.rollback) {
112-
const restored = await manager.rollback('object', 'test_object', 1);
107+
const restored = await manager.rollback('object', 'test_object', 1);
113108

114-
expect(restored).toBeDefined();
115-
expect((restored as any).label).toBe('Version 1');
116-
}
109+
expect(restored).toBeDefined();
110+
expect((restored as any).label).toBe('Version 1');
117111

118112
// Verify current metadata is version 1
119113
const current = await manager.get('object', 'test_object');
@@ -143,13 +137,11 @@ describe('Metadata History', () => {
143137
await manager.register('object', 'test_object', version2);
144138

145139
// Compare versions
146-
if (manager.diff) {
147-
const diffResult = await manager.diff('object', 'test_object', 1, 2);
140+
const diffResult = await manager.diff('object', 'test_object', 1, 2);
148141

149-
expect(diffResult.identical).toBe(false);
150-
expect(diffResult.patch!.length).toBeGreaterThan(0);
151-
expect(diffResult.summary).toContain('modified');
152-
}
142+
expect(diffResult.identical).toBe(false);
143+
expect(diffResult.patch!.length).toBeGreaterThan(0);
144+
expect(diffResult.summary).toContain('modified');
153145
});
154146

155147
it('should handle history query with filters', async () => {
@@ -164,22 +156,20 @@ describe('Metadata History', () => {
164156
await new Promise(resolve => setTimeout(resolve, 10));
165157
}
166158

167-
if (manager.getHistory) {
168-
// Query with limit
169-
const limitedHistory = await manager.getHistory('object', 'test_object', {
170-
limit: 3,
171-
});
159+
// Query with limit
160+
const limitedHistory = await manager.getHistory('object', 'test_object', {
161+
limit: 3,
162+
});
172163

173-
expect(limitedHistory.records.length).toBeLessThanOrEqual(3);
174-
expect(limitedHistory.total).toBeGreaterThanOrEqual(5);
164+
expect(limitedHistory.records.length).toBeLessThanOrEqual(3);
165+
expect(limitedHistory.total).toBeGreaterThanOrEqual(5);
175166

176-
// Query with operation type filter
177-
const createHistory = await manager.getHistory('object', 'test_object', {
178-
operationType: 'create',
179-
});
167+
// Query with operation type filter
168+
const createHistory = await manager.getHistory('object', 'test_object', {
169+
operationType: 'create',
170+
});
180171

181-
expect(createHistory.records.every(r => r.operationType === 'create')).toBe(true);
182-
}
172+
expect(createHistory.records.every(r => r.operationType === 'create')).toBe(true);
183173
});
184174

185175
it('should skip history record when checksum is unchanged', async () => {
@@ -194,23 +184,19 @@ describe('Metadata History', () => {
194184
// Re-register with exact same content
195185
await manager.register('object', 'test_object', objectDef);
196186

197-
if (manager.getHistory) {
198-
const history = await manager.getHistory('object', 'test_object');
187+
const history = await manager.getHistory('object', 'test_object');
199188

200-
// Should only have one history record (the create)
201-
// The second register should be skipped due to identical checksum
202-
expect(history.records.length).toBe(1);
203-
}
189+
// Should only have one history record (the create)
190+
// The second register should be skipped due to identical checksum
191+
expect(history.records.length).toBe(1);
204192
});
205193

206194
it('should return empty history for non-existent metadata', async () => {
207-
if (manager.getHistory) {
208-
const history = await manager.getHistory('object', 'nonexistent');
195+
const history = await manager.getHistory('object', 'nonexistent');
209196

210-
expect(history.records).toEqual([]);
211-
expect(history.total).toBe(0);
212-
expect(history.hasMore).toBe(false);
213-
}
197+
expect(history.records).toEqual([]);
198+
expect(history.total).toBe(0);
199+
expect(history.hasMore).toBe(false);
214200
});
215201

216202
it('should throw error when rolling back to non-existent version', async () => {
@@ -219,10 +205,8 @@ describe('Metadata History', () => {
219205
label: 'Test',
220206
});
221207

222-
if (manager.rollback) {
223-
await expect(
224-
manager.rollback('object', 'test_object', 999)
225-
).rejects.toThrow();
226-
}
208+
await expect(
209+
manager.rollback('object', 'test_object', 999)
210+
).rejects.toThrow();
227211
});
228212
});

0 commit comments

Comments
 (0)