| ... | @@ -5382,7 +5382,7 @@ it.effect("keeps the diff cached across a file being ticked off", () => | ... | @@ -5382,7 +5382,7 @@ it.effect("keeps the diff cached across a file being ticked off", () => |
| 5382 | yield* service.diff(reference); | 5382 | yield* service.diff(reference); |
| 5383 | yield* service.filesViewed(reference); | 5383 | yield* service.filesViewed(reference); |
| 5384 | | 5384 | |
| 5385 | // The press forgets only the reader's own ticks: a diff of any size survives it. | 5385 | // The press forgets only the reader's own ticks; cached diffs survive it. |
| 5386 | assert.strictEqual(diffReads, 1); | 5386 | assert.strictEqual(diffReads, 1); |
| 5387 | assert.strictEqual(viewedReads, 2); | 5387 | assert.strictEqual(viewedReads, 2); |
| 5388 | | 5388 | |
| ... | @@ -5397,6 +5397,72 @@ it.effect("keeps the diff cached across a file being ticked off", () => | ... | @@ -5397,6 +5397,72 @@ it.effect("keeps the diff cached across a file being ticked off", () => |
| 5397 | }), | 5397 | }), |
| 5398 | ); | 5398 | ); |
| 5399 | | 5399 | |
| | 5400 | it.effect("returns large diff slices intact without retaining them in either cache", () => |
| | 5401 | Effect.gen(function* () { |
| | 5402 | let reads = 0; |
| | 5403 | const patch = "\u{1f4bb}".repeat(140_000); |
| | 5404 | const service = yield* makeService({ |
| | 5405 | projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })], |
| | 5406 | providers: [ |
| | 5407 | fakeProvider("github", { |
| | 5408 | getDiff: () => |
| | 5409 | Effect.sync(() => { |
| | 5410 | reads += 1; |
| | 5411 | return { patch, truncated: false, nextCursor: "2" }; |
| | 5412 | }), |
| | 5413 | }), |
| | 5414 | ], |
| | 5415 | }); |
| | 5416 | const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 }; |
| | 5417 | for (const input of [ |
| | 5418 | reference, |
| | 5419 | { ...reference, cursor: "2" }, |
| | 5420 | { ...reference, commit: "a".repeat(40) }, |
| | 5421 | ]) { |
| | 5422 | const before = reads; |
| | 5423 | assert.deepStrictEqual(yield* service.diff(input), { |
| | 5424 | patch, |
| | 5425 | truncated: false, |
| | 5426 | nextCursor: "2", |
| | 5427 | }); |
| | 5428 | assert.deepStrictEqual(yield* service.diff(input), { |
| | 5429 | patch, |
| | 5430 | truncated: false, |
| | 5431 | nextCursor: "2", |
| | 5432 | }); |
| | 5433 | assert.strictEqual(reads, before + 2); |
| | 5434 | } |
| | 5435 | }), |
| | 5436 | ); |
| | 5437 | |
| | 5438 | it.effect("caches a small replacement after releasing a large diff", () => |
| | 5439 | Effect.gen(function* () { |
| | 5440 | let reads = 0; |
| | 5441 | const largePatch = "x".repeat(300_000); |
| | 5442 | const service = yield* makeService({ |
| | 5443 | projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })], |
| | 5444 | providers: [ |
| | 5445 | fakeProvider("github", { |
| | 5446 | getDiff: () => |
| | 5447 | Effect.sync(() => { |
| | 5448 | reads += 1; |
| | 5449 | return { |
| | 5450 | patch: reads === 1 ? largePatch : "@@ small replacement", |
| | 5451 | truncated: false, |
| | 5452 | nextCursor: null, |
| | 5453 | }; |
| | 5454 | }), |
| | 5455 | }), |
| | 5456 | ], |
| | 5457 | }); |
| | 5458 | const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 }; |
| | 5459 | assert.strictEqual((yield* service.diff(reference)).patch, largePatch); |
| | 5460 | assert.strictEqual((yield* service.diff(reference)).patch, "@@ small replacement"); |
| | 5461 | assert.strictEqual((yield* service.diff(reference)).patch, "@@ small replacement"); |
| | 5462 | assert.strictEqual(reads, 2); |
| | 5463 | }), |
| | 5464 | ); |
| | 5465 | |
| 5400 | const environmentViewedProvider = ( | 5466 | const environmentViewedProvider = ( |
| 5401 | revisions: Map<string, string>, | 5467 | revisions: Map<string, string>, |
| 5402 | asked: Array<ReadonlyArray<string>>, | 5468 | asked: Array<ReadonlyArray<string>>, |