Skip to content

Commit e3a1b83

Browse files
committed
Clean up attribution: remove debug logging, unused parameter, and spike test
Remove console.log/warn/error statements used during development, drop unused _identities parameter from useAttribution() (identities flow through AttributionContext), and delete the stale spike test that documented the old Automerge Text API patch format.
1 parent adb2ae3 commit e3a1b83

6 files changed

Lines changed: 11 additions & 188 deletions

File tree

hub-client/src/components/Editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export default function Editor({ project, files, fileContents, onDisconnect, onC
373373
return false;
374374
} catch { return false; }
375375
}, [currentFormat, astJson]);
376-
const attribution = useAttribution(attributionEnabled ? (currentFile?.path ?? null) : null, identities ?? {}, displayContent);
376+
const attribution = useAttribution(attributionEnabled ? (currentFile?.path ?? null) : null, displayContent);
377377
const attributionContextValue = attribution ? {
378378
attributionMap: attribution.attributionMap,
379379
byteToCharMap: attribution.byteToCharMap,

hub-client/src/components/render/ReactAstDebugRenderer.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,7 @@ const AstRenderer = ({ ast, onNavigateToDocument, setAst }: {
544544
const astContext = ast.astContext;
545545

546546
const nodeAttributionValue = useMemo(() => {
547-
if (!astContext || !attributionCtx) {
548-
if (!astContext) console.warn('[ast-debug] No astContext in AST JSON');
549-
if (!attributionCtx) console.warn('[ast-debug] No attribution context (hook returned null)');
550-
return null;
551-
}
547+
if (!astContext || !attributionCtx) return null;
552548

553549
try {
554550
// Populate files[0].content from the Automerge source text
@@ -577,8 +573,7 @@ const AstRenderer = ({ ast, onNavigateToDocument, setAst }: {
577573
attributionCtx.identities,
578574
),
579575
};
580-
} catch (err) {
581-
console.error('[ast-debug] Failed to build NodeAttribution:', err);
576+
} catch {
582577
return null;
583578
}
584579
}, [astContext, attributionCtx]);

hub-client/src/hooks/useAttribution.test.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ const mockUpdateAttributionMap = vi.mocked(updateAttributionMap);
3939
const mockBuildByteToCharMap = vi.mocked(buildByteToCharMap);
4040
const mockGetFileHandle = vi.mocked(getFileHandle);
4141

42-
const TEST_IDENTITIES = {
43-
actor1: { name: 'Alice', color: '#E91E63' },
44-
actor2: { name: 'Bob', color: '#2196F3' },
45-
};
46-
4742
function createMockMap(overrides?: Partial<AttributionMap>): AttributionMap {
4843
return {
4944
entries: [{ actor: 'actor1', time: 1000 }],
@@ -68,7 +63,7 @@ describe('useAttribution', () => {
6863
mockGetFileHandle.mockReturnValue(null);
6964

7065
const { result } = renderHook(() =>
71-
useAttribution('index.qmd', TEST_IDENTITIES, 'hello')
66+
useAttribution('index.qmd', 'hello')
7267
);
7368

7469
expect(result.current).toBeNull();
@@ -86,7 +81,7 @@ describe('useAttribution', () => {
8681
);
8782

8883
const { result } = renderHook(() =>
89-
useAttribution('index.qmd', TEST_IDENTITIES, 'hello')
84+
useAttribution('index.qmd', 'hello')
9085
);
9186

9287
// Initially null while building
@@ -112,7 +107,7 @@ describe('useAttribution', () => {
112107
mockUpdateAttributionMap.mockReturnValue(updatedMap);
113108

114109
const { result, rerender } = renderHook(
115-
({ text }) => useAttribution('index.qmd', TEST_IDENTITIES, text),
110+
({ text }) => useAttribution('index.qmd', text),
116111
{ initialProps: { text: 'hello' } },
117112
);
118113

@@ -146,7 +141,7 @@ describe('useAttribution', () => {
146141
});
147142

148143
const { result, rerender } = renderHook(
149-
({ text }) => useAttribution('index.qmd', TEST_IDENTITIES, text),
144+
({ text }) => useAttribution('index.qmd', text),
150145
{ initialProps: { text: 'hello' } },
151146
);
152147

@@ -183,7 +178,7 @@ describe('useAttribution', () => {
183178
.mockResolvedValueOnce(createMockMap({ processedHistoryIndex: 2 }));
184179

185180
const { result, rerender } = renderHook(
186-
({ path }) => useAttribution(path, TEST_IDENTITIES, 'hello'),
181+
({ path }) => useAttribution(path, 'hello'),
187182
{ initialProps: { path: 'file1.qmd' } },
188183
);
189184

@@ -217,7 +212,7 @@ describe('useAttribution', () => {
217212
mockBuildAttributionMap.mockReturnValue(new Promise(() => {})); // never resolves
218213

219214
const { unmount } = renderHook(() =>
220-
useAttribution('index.qmd', TEST_IDENTITIES, 'hello')
215+
useAttribution('index.qmd', 'hello')
221216
);
222217

223218
expect(mockBuildAttributionMap).toHaveBeenCalledTimes(1);

hub-client/src/hooks/useAttribution.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const DEBOUNCE_MS = 500;
4949

5050
export function useAttribution(
5151
filePath: string | null,
52-
_identities: Record<string, ActorIdentity>,
5352
sourceText: string,
5453
): UseAttributionResult | null {
5554
const [result, setResult] = useState<UseAttributionResult | null>(null);
@@ -79,28 +78,24 @@ export function useAttribution(
7978

8079
const handle = getFileHandle(path);
8180
if (!handle) {
82-
console.warn('[attribution] No file handle for', path);
8381
setResult(null);
8482
mapRef.current = null;
8583
return;
8684
}
8785

88-
console.log('[attribution] Starting build for', path);
8986
buildAttributionMap(handle, 'text', controller.signal).then(map => {
9087
if (controller.signal.aborted) return;
9188

9289
if (map) {
93-
console.log('[attribution] Build complete:', map.entries.length, 'chars,', map.processedHistoryIndex, 'history entries');
9490
const byteToChar = buildByteToCharMap(sourceTextRef.current);
9591
mapRef.current = map;
9692
setResult({ attributionMap: map, byteToCharMap: byteToChar });
9793
} else {
98-
console.warn('[attribution] Build returned null');
9994
mapRef.current = null;
10095
setResult(null);
10196
}
102-
}).catch(err => {
103-
console.error('[attribution] Build failed:', err);
97+
}).catch(() => {
98+
// Build failed — leave result as-is
10499
});
105100
}, []);
106101

hub-client/src/services/attribution-spike.test.ts

Lines changed: 0 additions & 151 deletions
This file was deleted.

hub-client/src/services/attribution.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ export async function buildAttributionMap(
144144
const viewable = handle as unknown as ViewableHandle;
145145
const history = viewable.history();
146146

147-
console.log('[attribution:build] history:', history ? history.length + ' entries' : 'undefined');
148-
149147
if (!history) return null;
150148

151149
if (history.length === 0) {
@@ -180,7 +178,6 @@ export async function buildAttributionMap(
180178
const decodedCurr = decodeHeads(currHeads as Parameters<typeof decodeHeads>[0]);
181179
let patches: unknown[];
182180

183-
try {
184181
if (prevHeads === null) {
185182
patches = diff(
186183
viewable.doc() as Parameters<typeof diff>[0],
@@ -195,14 +192,6 @@ export async function buildAttributionMap(
195192
decodedCurr as unknown as Heads,
196193
);
197194
}
198-
} catch (err) {
199-
console.error('[attribution:build] diff() failed at history entry', i, err);
200-
throw err;
201-
}
202-
203-
if (i < 3 && patches.length > 0) {
204-
console.log('[attribution:build] Entry', i, 'patches:', JSON.stringify(patches.slice(0, 3)));
205-
}
206195

207196
for (const patch of patches) {
208197
if (isTextPatch(patch, textFieldName)) {

0 commit comments

Comments
 (0)