π¬ A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots π
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
fix(guides): close the two duplicate gaps found in review
davbio85866234963f
diff --git a/src/core/guides/__tests__/duplicate.test.ts b/src/core/guides/__tests__/duplicate.test.tsindex dfc17b7..9ec4d54 100644--- a/src/core/guides/__tests__/duplicate.test.ts+++ b/src/core/guides/__tests__/duplicate.test.ts@@ -97,7 +97,6 @@ describe('duplicateGuide', () => {expect(copy?.guide.stepIds).toEqual(copy?.steps.map((s) => s.id));expect(copy?.steps.every((s) => s.guideId === copyId)).toBe(true);- // Each copied step points at a screenshot of its own, not the source's.const copiedIds = copy?.steps.map((s) => s.screenshotId);expect(copiedIds).not.toContain('sc1');expect(copiedIds).not.toContain('sc2');@@ -156,7 +155,6 @@ describe('duplicateGuide', () => {const copyId = await duplicateGuide('g1');expect(await db.transcripts.where('guideId').equals(copyId!).count()).toBe(0);- // The spoken original still rides along on the step itself.const copy = await getGuide(copyId!);expect(copy?.steps[0].narratedDescription).toBe('what I said');});@@ -165,7 +163,6 @@ describe('duplicateGuide', () => {await seedGuide('g1', { stepIds: ['s1'] });await db.steps.add(makeStep({ id: 's1', guideId: 'g1', screenshotId: 'sc1' }));await db.screenshots.add(makeScreenshot({ id: 'sc1', stepId: 's1' }));- // Leaves the superseded 'sc1' row behind for version history to revert to.await replaceScreenshot('s1', new Blob(['new'], { type: 'image/png' }), { width: 10, height: 10 });expect(await db.screenshots.where('stepId').equals('s1').count()).toBe(2);@@ -186,6 +183,31 @@ describe('duplicateGuide', () => {expect(copy?.staging).toBeUndefined();});+ it('clears the pending-AI flag, which nothing would ever resolve on the copy', async () => {+ await seedGuide('g1', { stepIds: ['s1'] });+ await db.steps.add(makeStep({ id: 's1', guideId: 'g1', aiPending: true }));++ const copyId = await duplicateGuide('g1');+ const copy = await getGuide(copyId!);++ expect(copy?.steps[0].aiPending).toBeUndefined();+ expect((await db.steps.get('s1'))?.aiPending).toBe(true);+ });++ it('drops a screenshot row that names no step of this guide rather than copying it unkeyed', async () => {+ await seedGuide('g1', { stepIds: ['s1'] });+ await db.steps.add(makeStep({ id: 's1', guideId: 'g1', screenshotId: 'sc1' }));+ await db.screenshots.add(makeScreenshot({ id: 'sc1', stepId: 'gone' }));++ const copyId = await duplicateGuide('g1');+ const copy = await getGuide(copyId!);++ expect(copy?.steps).toHaveLength(1);+ expect(copy?.steps[0].screenshotId).toBeUndefined();+ expect(copy?.screenshots.size).toBe(0);+ expect(await db.screenshots.count()).toBe(1);+ });+it('announces the new guide on the guides channel', async () => {await seedGuide('g1', { stepIds: [] });await duplicateGuide('g1');diff --git a/src/core/guides/service.ts b/src/core/guides/service.tsindex 0028272..9f76555 100644--- a/src/core/guides/service.ts+++ b/src/core/guides/service.ts@@ -211,34 +211,19 @@ export async function createStep(step: Step): Promise<void> {await db.steps.add(step);}-/**- * Copies a guide into a new, independent one β the long recording a user then trims down into- * several shorter guides. Steps and screenshot rows are copied outright under fresh ids, so the- * copy shares nothing that can be edited: {@link updateScreenshotEdits} writes a row in place, and- * a shared row would mean annotating one guide silently annotated the other.- *- * Snapshots are deliberately not carried over β the copy's original is the moment it was made, and- * a snapshot's screenshot rows point at ids that only exist in the source. Transcripts are not- * carried over either: their lines key to step ids that all changed here, and a verbatim transcript- * is the most sensitive thing stored, so it stays with the one guide the user recorded it on. The- * spoken text itself survives per step in `narratedDescription`, so "restore what I said" still- * works in the copy.- */export async function duplicateGuide(guideId: string): Promise<string | null> {const copyId = await db.transaction('rw', db.guides, db.steps, db.screenshots, async () => {const guide = await db.guides.get(guideId);if (!guide) return null;const steps = await db.steps.where('guideId').equals(guideId).sortBy('index');- // By id, not by stepId: replaceScreenshot leaves the superseded rows behind for version history- // to revert to, and the copy has no history that could ever reach them.- const screenshots = await db.screenshots- .where('id')- .anyOf(steps.map((s) => s.screenshotId).filter((id): id is string => !!id))- .toArray();+ const currentScreenshotIds = steps.map((step) => step.screenshotId).filter((id): id is string => !!id);const newGuideId = crypto.randomUUID();const stepIdMap = new Map(steps.map((step) => [step.id, crypto.randomUUID()]));- const screenshotIdMap = new Map(screenshots.map((row) => [row.id, crypto.randomUUID()]));+ const screenshotsBelongingToTheseSteps = (+ await db.screenshots.where('id').anyOf(currentScreenshotIds).toArray()+ ).filter((row) => stepIdMap.has(row.stepId));+ const screenshotIdMap = new Map(screenshotsBelongingToTheseSteps.map((row) => [row.id, crypto.randomUUID()]));const now = Date.now();const { staging: _staging, ...rest } = guide;@@ -258,11 +243,12 @@ export async function duplicateGuide(guideId: string): Promise<string | null> {id: stepIdMap.get(step.id)!,guideId: newGuideId,index,+ aiPending: undefined,screenshotId: step.screenshotId ? screenshotIdMap.get(step.screenshotId) : undefined,})),);await db.screenshots.bulkAdd(- screenshots.map((row) => ({+ screenshotsBelongingToTheseSteps.map((row) => ({...row,id: screenshotIdMap.get(row.id)!,stepId: stepIdMap.get(row.stepId)!,