Files
anonymous_github/test/anonymize-literal-performance.test.js
T
Thomas Durieux 6434337923 perf: bound request work and resource usage (#866)
* perf: bound request work and resource usage

* fix: address performance review regressions

* fix: guard content expiration and dashboard state

* fix: tolerate cache outages and retire derived paths

* fix: revalidate expiration claims and status pagination

* fix: retry interrupted repository metadata cleanup

* fix: retire obsolete content cache storage

* fix: activate tree metadata and recheck expiration claims

* fix: fence cache publication across expiration

* fix: recover staged trees and enforce cache lifecycle cleanup

* fix: prune expired transforms during database outages

* fix: finish conference removals and reload expiration candidates
2026-10-08 03:38:19 +01:00

43 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { expect } = require("chai");
require("ts-node/register/transpile-only");
const { Readable } = require("stream");
const { ContentAnonimizer, AnonymizeTransformer } = require("../src/core/anonymize-utils");
describe("literal term presence checks", function () {
it("serves a large JavaScript file with absent names within the anonymization deadline", async function () {
this.timeout(10000); // Includes worker startup; the matcher retains its one-second deadline.
const input = Buffer.from('function render(){return "application content";}\n'.repeat(65000));
const transformer = new AnonymizeTransformer({
filePath: "main.js",
terms: Array.from({ length: 20 }, (_, i) => `Researcher${i}`),
image: true,
link: true,
});
const chunks = [];
Readable.from([input.subarray(0, 65536), input.subarray(65536)]).pipe(transformer);
for await (const chunk of transformer) chunks.push(chunk);
expect(Buffer.concat(chunks).equals(input)).to.equal(true);
});
it("preserves RE2 replacements, Unicode case folding, and boundaries", function () {
const cases = [
{ terms: ["Alice"], text: "ALICE Alice Álîce Malice Alice2 éAlice Aliceé" },
{ terms: ["Davo"], text: "Davó DAVO Davoé éDavo" },
{ terms: ["Davó"], text: "Davo DAVÓ Davó" },
{ terms: ["k", "s"], text: "k K K s S ſ éK ſé" },
{ terms: ["Σ", "Ж", "研究"], text: "Σ σ ς Ж ж 研究" },
{ terms: ["@Alice", "Alice-Bob"], text: "@Álice @Alice Alice-Bob" },
{ terms: ["Alice=>Bob", "Bob=>$&"], text: "Alice and Bob" },
{ terms: ["a.*b", "a(?=b)", "a\\.b"], text: "a.b ab axxb" },
];
for (const { terms, text } of cases) {
const reference = new ContentAnonimizer({ terms });
// Compare against the existing matcher without its optional shortcut.
for (const term of reference.compiledTerms) delete term.literalPrefilter;
const optimized = new ContentAnonimizer({ terms });
expect(optimized.anonymize(text)).to.equal(reference.anonymize(text));
expect(optimized.wasAnonymized).to.equal(reference.wasAnonymized);
}
});
});