Skip to content

Commit 26084cd

Browse files
Merge pull request #286 from apasel422/tidy
Miscellaneous code cleanup in simulator
2 parents 66c34d0 + da6b933 commit 26084cd

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

impl/src/backend.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface Impression {
1818
impressionSite: string;
1919
intermediarySite: string | undefined;
2020
conversionSites: Set<string>;
21-
conversionCallers: Set<string>;
21+
conversionCallers: ReadonlySet<string>;
2222
timestamp: Temporal.Instant;
2323
lifetime: Temporal.Duration;
2424
histogramIndex: number;
@@ -39,9 +39,9 @@ interface ValidatedConversionOptions {
3939
epsilon: number;
4040
histogramSize: number;
4141
lookback: Temporal.Duration;
42-
matchValues: Set<number>;
43-
impressionSites: Set<string>;
44-
impressionCallers: Set<string>;
42+
matchValues: ReadonlySet<number>;
43+
impressionSites: ReadonlySet<string>;
44+
impressionCallers: ReadonlySet<string>;
4545
credit: readonly number[];
4646
value: number;
4747
maxValue: number;
@@ -105,15 +105,15 @@ export class Backend {
105105
this.#delegate = delegate;
106106
}
107107

108-
get epochStarts(): Iterable<[string, Temporal.Instant]> {
109-
return this.#epochStartStore.entries();
108+
get epochStarts(): ReadonlyMap<string, Temporal.Instant> {
109+
return this.#epochStartStore;
110110
}
111111

112-
get privacyBudgetEntries(): Iterable<Readonly<PrivacyBudgetStoreEntry>> {
112+
get privacyBudgetEntries(): ReadonlyArray<Readonly<PrivacyBudgetStoreEntry>> {
113113
return this.#privacyBudgetStore;
114114
}
115115

116-
get impressions(): Iterable<Readonly<Impression>> {
116+
get impressions(): ReadonlyArray<Readonly<Impression>> {
117117
return this.#impressions;
118118
}
119119

@@ -517,7 +517,7 @@ export class Backend {
517517
}
518518

519519
#fillHistogramWithLastNTouchAttribution(
520-
matchedImpressions: Set<Impression>,
520+
matchedImpressions: ReadonlySet<Impression>,
521521
histogramSize: number,
522522
value: number,
523523
credit: readonly number[],
@@ -618,7 +618,7 @@ export class Backend {
618618
);
619619
}
620620

621-
#zeroBudgetForSites(sites: Set<string>): void {
621+
#zeroBudgetForSites(sites: ReadonlySet<string>): void {
622622
if (sites.size === 0) {
623623
throw new RangeError("need to specify at least one site when forgetting");
624624
}

impl/src/clear.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void test("clear-site-state", async () => {
5757
backend.clearState(["conv-one.example"], false);
5858

5959
assert.equal(
60-
[...backend.impressions].length,
60+
backend.impressions.length,
6161
siteTable.length,
6262
"All the impressions remain unaffected",
6363
);
@@ -88,9 +88,9 @@ void test("forget-all-sites", async () => {
8888
const backend = await setupImpressions({ now, ...defaultConfig });
8989
backend.clearState([], true);
9090

91-
assert.equal([...backend.impressions].length, 0);
92-
assert.equal([...backend.privacyBudgetEntries].length, 0);
93-
assert.equal([...backend.epochStarts].length, 0);
91+
assert.deepEqual(backend.impressions, []);
92+
assert.deepEqual(backend.privacyBudgetEntries, []);
93+
assert.deepEqual(backend.epochStarts, new Map());
9494
assert.deepEqual(
9595
backend.lastBrowsingHistoryClear,
9696
Temporal.Instant.from(now),
@@ -104,12 +104,12 @@ void test("forget-one-site-impressions", async () => {
104104
backend.clearState(["imp-one.example"], true);
105105

106106
assert.deepEqual(
107-
[...backend.impressions].map((i) => i.impressionSite),
107+
backend.impressions.map((i) => i.impressionSite),
108108
siteTable.map((i) => i.impression).filter((i) => i !== "imp-one.example"),
109109
"Impressions for the affected site are removed",
110110
);
111-
assert.equal([...backend.privacyBudgetEntries].length, 0);
112-
assert.equal([...backend.epochStarts].length, 0);
111+
assert.deepEqual(backend.privacyBudgetEntries, []);
112+
assert.deepEqual(backend.epochStarts, new Map());
113113
assert.deepEqual(
114114
backend.lastBrowsingHistoryClear,
115115
Temporal.Instant.from(now),
@@ -128,15 +128,15 @@ void test("forget-one-site-conversions", async () => {
128128
});
129129
assert.ok(before.unencryptedHistogram!.some((v) => v > 0));
130130

131-
assert.ok([...backend.privacyBudgetEntries].length > 0);
132-
assert.equal([...backend.epochStarts].length, 1);
131+
assert.ok(backend.privacyBudgetEntries.length > 0);
132+
assert.equal(backend.epochStarts.size, 1);
133133

134134
backend.clearState(["conv-one.example"], true);
135135

136136
// Conversions are unaffected, and conversion state is gone.
137-
assert.equal([...backend.impressions].length, siteTable.length);
138-
assert.equal([...backend.privacyBudgetEntries].length, 0);
139-
assert.equal([...backend.epochStarts].length, 0);
137+
assert.equal(backend.impressions.length, siteTable.length);
138+
assert.deepEqual(backend.privacyBudgetEntries, []);
139+
assert.deepEqual(backend.epochStarts, new Map());
140140
assert.deepEqual(
141141
backend.lastBrowsingHistoryClear,
142142
Temporal.Instant.from(now),
@@ -151,7 +151,7 @@ void test("forget-one-site-conversions", async () => {
151151
assert.ok(after.unencryptedHistogram!.every((v) => v === 0));
152152

153153
// Privacy budget entries aren't added; this epoch is off-limits.
154-
assert.equal([...backend.privacyBudgetEntries].length, 0);
154+
assert.deepEqual(backend.privacyBudgetEntries, []);
155155
// The epoch start will be initialized.
156-
assert.equal([...backend.epochStarts].length, 1);
156+
assert.equal(backend.epochStarts.size, 1);
157157
});

impl/src/e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function runTest(
9393
});
9494

9595
for (const event of tc.events) {
96-
const newNow = now.add({ seconds: event.seconds });
96+
const newNow = Temporal.Instant.fromEpochMilliseconds(event.seconds * 1e3);
9797
if (Temporal.Instant.compare(newNow, now) <= 0) {
9898
throw new RangeError(
9999
"events must have strictly increasing seconds fields",

impl/src/fixture.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export interface TestConfig {
1717
privacyBudgetEpochDays: number;
1818
}
1919

20-
export function makeBackend(overrideConfig?: Readonly<TestConfig>): Backend {
21-
const config = overrideConfig ?? defaultConfig;
20+
export function makeBackend(
21+
config: Readonly<TestConfig> = defaultConfig,
22+
): Backend {
2223
const now = config.now
2324
? Temporal.Instant.from(config.now)
2425
: new Temporal.Instant(0n);

0 commit comments

Comments
 (0)