diff --git a/src/cache-keys.3tg.md b/src/cache-keys.3tg.md
new file mode 100644
index 00000000..668e9f4b
--- /dev/null
+++ b/src/cache-keys.3tg.md
@@ -0,0 +1,188 @@
+# Exported functions from "src/cache-keys.ts"
+
+
+
+## hashString(strValue: string)
+
+These are the functional requirements for function `hashString`.
+
+| test name | strValue | hashString |
+| --------- | -------- | ------------------------------------------------------------------ |
+| | '' | 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' |
+| | 'abc' | 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' |
+| | '😉' | '62e785e976a0c101316f55c805ee6275ac3cb4eaae2f8e4f3d725c2bd1cfa52f' |
+
+## hashJson(jsonValue: unknown)
+
+These are the functional requirements for function `hashJson`.
+
+| test name | jsonValue | hashJson |
+| --------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------ |
+| | undefined | throw 'The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined' |
+| | null | '74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b' |
+| | NaN | '74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b' |
+| | new Date('invalid') | '74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b' |
+| | ()=>{} | throw 'The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined' |
+| | 0 | '5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9' |
+| | '' | '12ae32cb1ec02d01eda3581b127c1fee3b0dc53572ed6baf239721a03d82e126' |
+| | {} | '44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a' |
+| | {valid:true} | '8daf09a6fc31937457dd77e9c25ce4b21349d605b561a8c5d557841bf964c9a0' |
+
+### Posible bug
+
+1. The type of `jsonValue` should be reduced as not all types can be converted/preserved by JSON
+
+## normalizeContentForHash(content: string)
+
+These are the functional requirements for function `normalizeContentForHash`.
+
+| test name | content | normalizeContentForHash |
+| --------- | --------------------- | ----------------------- |
+| | '' | '' |
+| | '\r\n' | '' |
+| | ' \r\n ' | '' |
+| | ' \n ' | '' |
+| | 'abc' | 'abc' |
+| | '\r\nabc' | 'abc' |
+| | 'abc\r\n' | 'abc' |
+| | 'abc\r\n pqr \r\nxyz' | 'abc\n pqr \nxyz' |
+
+## extractTaggedBlock(propromptTextmpt: string, tag: "instructions" | "content")
+
+These are the functional requirements for function `extractTaggedBlock`.
+
+### Tests for tag "instructions"
+
+| test name | promptText | tag | extractTaggedBlock |
+| --------- | -------------------------------------------------------------------------- | -------------- | ------------------ |
+| | '' | 'instructions' | null |
+| | '' | 'instructions' | null |
+| | '' | 'instructions' | '' |
+| | 'Do this' | 'instructions' | 'Do this' |
+| | ' Do this ' | 'instructions' | 'Do this' |
+| | 'Part 1\nPart 2' | 'instructions' | 'Part 1\nPart 2' |
+| | 'Do thisText' | 'instructions' | 'Do this' |
+| | 'Do thisDo that' | 'instructions' | 'Do this' |
+| | 'Do this' | 'instructions' | 'Do this' |
+
+### Tests for tag "content"
+
+We assume that actually `tag`'s value can be any string value.
+
+### Possible bugs
+
+1. `extractTaggedBlock` does not support nested tags of the some type.
+
+| test name | promptText | tag | extractTaggedBlock |
+| ----------------- | --------------------------------------------------------------- | -------------- | ------------------ |
+| [bug] Nested Tags | 'ABC' | 'instructions' | 'AB' |
+
+Note: This test is skipped.
+
+## buildPromptHash(prompt: string)
+
+These are the functional requirements for function `buildPromptHash`.
+
+| test name | prompt | buildPromptHash |
+| --------- | ------------------------------------------ | ------------------------------------------------------------------ |
+| | '' | 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' |
+| | 'abc' | 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' |
+| | 'Do this' | '1d75e222aec1fbd4e394723435858f4f40bab950a79ee6c3d5ae048ac77aec70' |
+| | ' Do this ' | '1d75e222aec1fbd4e394723435858f4f40bab950a79ee6c3d5ae048ac77aec70' |
+| | 'A Do this B' | '1d75e222aec1fbd4e394723435858f4f40bab950a79ee6c3d5ae048ac77aec70' |
+| | 'Do this' | '1d75e222aec1fbd4e394723435858f4f40bab950a79ee6c3d5ae048ac77aec70' |
+| | ' Do this ' | '1d75e222aec1fbd4e394723435858f4f40bab950a79ee6c3d5ae048ac77aec70' |
+
+## buildPromptContentHash(promptFallbackContent: { prompt: string; fallbackContent?: string; })
+
+These are the functional requirements for function `buildPromptContentHash`.
+
+| test name | promptFallbackContent | buildPromptContentHash |
+| --------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
+| | {prompt: '', fallbackContent: ''} | null |
+| | {prompt: '', fallbackContent: 'abc'} | 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' |
+| | {prompt: '', fallbackContent: null} | null |
+| | {prompt: '', fallbackContent: undefined} | null |
+| | {prompt: '', fallbackContent: ''} | null |
+| | {prompt: '', fallbackContent: 'abc'} | null |
+| | {prompt: '', fallbackContent: null} | null |
+| | {prompt: '', fallbackContent: undefined} | null |
+| | {prompt: 'Text', fallbackContent: ''} | '71988c4d8e0803ba4519f0b2864c1331c14a1890bf8694e251379177bfedb5c3' |
+| | {prompt: 'Text', fallbackContent: 'abc'} | '71988c4d8e0803ba4519f0b2864c1331c14a1890bf8694e251379177bfedb5c3' |
+| | {prompt: 'Text', fallbackContent: null} | '71988c4d8e0803ba4519f0b2864c1331c14a1890bf8694e251379177bfedb5c3' |
+| | {prompt: 'Text', fallbackContent: undefined} | '71988c4d8e0803ba4519f0b2864c1331c14a1890bf8694e251379177bfedb5c3' |
+| | {prompt: 'ABC', fallbackContent: ''} | 'df7e70e5021544f4834bbee64a9e3789febc4be81470df629cad6ddb03320a5c' |
+| | {prompt: 'ABC', fallbackContent: 'abc'} | 'df7e70e5021544f4834bbee64a9e3789febc4be81470df629cad6ddb03320a5c' |
+| | {prompt: 'ABC', fallbackContent: null} | 'df7e70e5021544f4834bbee64a9e3789febc4be81470df629cad6ddb03320a5c' |
+| | {prompt: 'ABC', fallbackContent: undefined} | 'df7e70e5021544f4834bbee64a9e3789febc4be81470df629cad6ddb03320a5c' |
+| | {prompt: 'AB', fallbackContent: ''} | null |
+| | {prompt: 'AB', fallbackContent: 'abc'} | 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' |
+| | {prompt: 'AB', fallbackContent: null} | null |
+| | {prompt: 'AB', fallbackContent: undefined} | null |
+| | {prompt: 'No tags here', fallbackContent: ''} | null |
+| | {prompt: 'No tags here', fallbackContent: 'abc'} | 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' |
+| | {prompt: 'No tags here', fallbackContent: null} | null |
+| | {prompt: 'No tags here', fallbackContent: undefined} | null |
+
+## buildLengthKey(lengthArg: LengthArg)
+
+These are the functional requirements for function `buildLengthKey`.
+
+| test name | lengthArg | buildLengthKey |
+| --------- | --------------------------------- | --------------- |
+| | { kind:'preset', preset:'medium'} | 'preset:medium' |
+| | { kind:'chars', maxCharacters:10} | 'chars:10' |
+
+## buildLanguageKey(outputLanguage: OutputLanguage)
+
+These are the functional requirements for function `buildLanguageKey`.
+
+| test name | outputLanguage | buildLanguageKey |
+| --------- | ------------------------------------------ | ---------------- |
+| | {kind:'auto'} | 'auto' |
+| | {kind:'fixed', tag:'TAG', label:'English'} | 'TAG' |
+
+## buildExtractCacheKeyValue(cacheKey: { url: string; options: Record; formatVersion: number; })
+
+These are the functional requirements for function `buildExtractCacheKeyValue`.
+
+| test name | cacheKey | buildExtractCacheKeyValue |
+| --------- | ------------------------------------------------------ | ------------------------------------------------------------------ |
+| | {url:'https://localhost', options:{}, formatVersion:1} | '0b8b6f834c5f41ded2d14c4aa6e3e57e836985335da96f6e6ceb4863b020b6e8' |
+
+Note: It can be replaced with or made an alias of `hashJson`. `hashJson` should be made generic.
+
+## buildSummaryCacheKeyValue(summaryCacheKey: { contentHash: string; promptHash: string; model: string; lengthKey: string; languageKey: string; formatVersion: number; })
+
+These are the functional requirements for function `buildSummaryCacheKeyValue`.
+
+| test name | summaryCacheKey | buildSummaryCacheKeyValue |
+| --------- | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
+| | {contentHash:'1', promptHash:'2', model:'model', lengthKey:'1', languageKey:'English', formatVersion:1} | 'ab473a87b6e86f5630671862a4c4e933ca7a9f7dfdc6e8dde8e0c1692dd5ab64' |
+
+Note: It can be replaced with or made an alias of `hashJson`. `hashJson` should be made generic.
+
+## buildSlidesCacheKeyValue(slidesCacheKey: { url: string; settings: { ocr: boolean; outputDir: string; sceneThreshold: number; autoTuneThreshold: boolean; maxSlides: number; minDurationSeconds: number; }; formatVersion: number; })
+
+These are the functional requirements for function `buildSlidesCacheKeyValue`.
+
+| test name | slidesCacheKey | buildSlidesCacheKeyValue |
+| --------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
+| | {url:'url', settings:{ocr:true, outputDir:'.', sceneThreshold:0, autoTuneThreshold:true, maxSlides:1, minDurationSeconds:1}, formatVersion:1} | 'baa408bb0e376b3b2a100b575bfaf8bc26f539850cf3cf187ef810a95a40a600' |
+
+Note: It can be replaced with or made an alias of `hashJson`. `hashJson` should be made generic.
+
+## buildTranscriptCacheKeyValue(transcriptCacheKey: { url: string; namespace: string|null; formatVersion: number; fileMtime?: number|null; })
+
+These are the functional requirements for function `buildTranscriptCacheKeyValue`.
+
+| test name | transcriptCacheKey | buildTranscriptCacheKeyValue |
+| --------- | ----------------------------------------------------------------- | ------------------------------------------------------------------ |
+| | {url:'url', namespace:'ns', formatVersion:1, fileMtime:null} | '26243737dfcd6603f3823f35577d9a049ec328d3aaaf4349f67148f3bfc62332' |
+| | {url:'url', namespace:'ns', formatVersion:1, fileMtime:undefined} | '26243737dfcd6603f3823f35577d9a049ec328d3aaaf4349f67148f3bfc62332' |
+
+Note: It can be replaced with or made an alias of `hashJson`. `hashJson` should be made generic.
diff --git a/src/cache-keys.ts b/src/cache-keys.ts
index a8d22fd4..541ecf31 100644
--- a/src/cache-keys.ts
+++ b/src/cache-keys.ts
@@ -2,26 +2,26 @@ import { createHash } from "node:crypto";
import type { LengthArg } from "./flags.js";
import type { OutputLanguage } from "./language.js";
-export function hashString(value: string): string {
- return createHash("sha256").update(value).digest("hex");
+export function hashString(strValue: string): string {
+ return createHash("sha256").update(strValue).digest("hex");
}
-export function hashJson(value: unknown): string {
- return hashString(JSON.stringify(value));
+export function hashJson(jsonValue: unknown): string {
+ return hashString(JSON.stringify(jsonValue));
}
export function normalizeContentForHash(content: string): string {
return content.replaceAll("\r\n", "\n").trim();
}
-export function extractTaggedBlock(prompt: string, tag: "instructions" | "content"): string | null {
+export function extractTaggedBlock(promptText: string, tag: "instructions" | "content"): string | null {
const open = `<${tag}>`;
const close = `${tag}>`;
- const start = prompt.indexOf(open);
+ const start = promptText.indexOf(open);
if (start === -1) return null;
- const end = prompt.indexOf(close, start + open.length);
+ const end = promptText.indexOf(close, start + open.length);
if (end === -1) return null;
- return prompt.slice(start + open.length, end).trim();
+ return promptText.slice(start + open.length, end).trim();
}
export function buildPromptHash(prompt: string): string {
@@ -29,48 +29,33 @@ export function buildPromptHash(prompt: string): string {
return hashString(instructions.trim());
}
-export function buildPromptContentHash({
- prompt,
- fallbackContent,
-}: {
+export function buildPromptContentHash(promptFallbackContent: {
prompt: string;
fallbackContent?: string | null;
}): string | null {
+ const { prompt, fallbackContent } = promptFallbackContent;
const content = extractTaggedBlock(prompt, "content") ?? fallbackContent ?? null;
if (!content || content.trim().length === 0) return null;
return hashString(normalizeContentForHash(content));
}
export function buildLengthKey(lengthArg: LengthArg): string {
- return lengthArg.kind === "preset"
- ? `preset:${lengthArg.preset}`
- : `chars:${lengthArg.maxCharacters}`;
+ return lengthArg.kind === "preset" ? `preset:${lengthArg.preset}` : `chars:${lengthArg.maxCharacters}`;
}
export function buildLanguageKey(outputLanguage: OutputLanguage): string {
return outputLanguage.kind === "auto" ? "auto" : outputLanguage.tag;
}
-export function buildExtractCacheKeyValue({
- url,
- options,
- formatVersion,
-}: {
+export function buildExtractCacheKeyValue(cacheKey: {
url: string;
options: Record;
formatVersion: number;
}): string {
- return hashJson({ url, options, formatVersion });
+ return hashJson(cacheKey);
}
-export function buildSummaryCacheKeyValue({
- contentHash,
- promptHash,
- model,
- lengthKey,
- languageKey,
- formatVersion,
-}: {
+export function buildSummaryCacheKeyValue(summaryCacheKey: {
contentHash: string;
promptHash: string;
model: string;
@@ -78,21 +63,10 @@ export function buildSummaryCacheKeyValue({
languageKey: string;
formatVersion: number;
}): string {
- return hashJson({
- contentHash,
- promptHash,
- model,
- lengthKey,
- languageKey,
- formatVersion,
- });
+ return hashJson(summaryCacheKey);
}
-export function buildSlidesCacheKeyValue({
- url,
- settings,
- formatVersion,
-}: {
+export function buildSlidesCacheKeyValue(slidesCacheKey: {
url: string;
settings: {
ocr: boolean;
@@ -104,35 +78,14 @@ export function buildSlidesCacheKeyValue({
};
formatVersion: number;
}): string {
- return hashJson({
- url,
- settings: {
- ocr: settings.ocr,
- outputDir: settings.outputDir,
- sceneThreshold: settings.sceneThreshold,
- autoTuneThreshold: settings.autoTuneThreshold,
- maxSlides: settings.maxSlides,
- minDurationSeconds: settings.minDurationSeconds,
- },
- formatVersion,
- });
+ return hashJson(slidesCacheKey);
}
-export function buildTranscriptCacheKeyValue({
- url,
- namespace,
- formatVersion,
- fileMtime,
-}: {
+export function buildTranscriptCacheKeyValue(transcriptCacheKey: {
url: string;
namespace: string | null;
formatVersion: number;
fileMtime?: number | null;
}): string {
- return hashJson({
- url,
- namespace,
- fileMtime: fileMtime ?? null,
- formatVersion,
- });
+ return hashJson({ ...transcriptCacheKey, fileMtime: transcriptCacheKey.fileMtime ?? null });
}
diff --git a/tests/cache-keys.test.ts b/tests/cache-keys.test.ts
new file mode 100644
index 00000000..41ceb5ad
--- /dev/null
+++ b/tests/cache-keys.test.ts
@@ -0,0 +1,633 @@
+import { describe, expect, it } from "vitest";
+import * as __testedFile from "../src/cache-keys";
+
+describe("src/cache-keys.ts", () => {
+ describe("hashString", () => {
+ const { hashString } = __testedFile;
+ // strValue: string
+
+ it("should test hashString( mock-parameters.strValue 1 )", () => {
+ const strValue: Parameters[0] = "";
+ const __expectedResult: ReturnType =
+ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
+ expect(hashString(strValue)).toEqual(__expectedResult);
+ });
+
+ it("should test hashString( mock-parameters.strValue 2 )", () => {
+ const strValue: Parameters[0] = "abc";
+ const __expectedResult: ReturnType =
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
+ expect(hashString(strValue)).toEqual(__expectedResult);
+ });
+
+ it("should test hashString( mock-parameters.strValue 3 )", () => {
+ const strValue: Parameters[0] = "😉";
+ const __expectedResult: ReturnType =
+ "62e785e976a0c101316f55c805ee6275ac3cb4eaae2f8e4f3d725c2bd1cfa52f";
+ expect(hashString(strValue)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("hashJson", () => {
+ const { hashJson } = __testedFile;
+ // jsonValue: unknown
+
+ it("should test hashJson( mock-parameters.jsonValue 1 )", () => {
+ const jsonValue: Parameters[0] = "";
+ const __expectedResult: ReturnType =
+ "12ae32cb1ec02d01eda3581b127c1fee3b0dc53572ed6baf239721a03d82e126";
+ expect(hashJson(jsonValue)).toEqual(__expectedResult);
+ });
+
+ it("should test hashJson( mock-parameters.jsonValue 2 )", () => {
+ const jsonValue: Parameters[0] = () => {};
+ expect(() => hashJson(jsonValue)).toThrow(
+ 'The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined',
+ );
+ });
+
+ it("should test hashJson( mock-parameters.jsonValue 3 )", () => {
+ const jsonValue: Parameters[0] = 0;
+ const __expectedResult: ReturnType =
+ "5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9";
+ expect(hashJson(jsonValue)).toEqual(__expectedResult);
+ });
+
+ it("should test hashJson( mock-parameters.jsonValue 4 )", () => {
+ const jsonValue: Parameters[0] = NaN;
+ const __expectedResult: ReturnType =
+ "74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b";
+ expect(hashJson(jsonValue)).toEqual(__expectedResult);
+ });
+
+ it("should test hashJson( mock-parameters.jsonValue 5 )", () => {
+ const jsonValue: Parameters[0] = new Date("invalid");
+ const __expectedResult: ReturnType =
+ "74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b";
+ expect(hashJson(jsonValue)).toEqual(__expectedResult);
+ });
+
+ it("should test hashJson( mock-parameters.jsonValue 6 )", () => {
+ const jsonValue: Parameters[0] = null;
+ const __expectedResult: ReturnType =
+ "74234e98afe7498fb5daf1f36ac2d78acc339464f950703b8c019892f982b90b";
+ expect(hashJson(jsonValue)).toEqual(__expectedResult);
+ });
+
+ it("should test hashJson( mock-parameters.jsonValue 7 )", () => {
+ const jsonValue: Parameters[0] = undefined;
+ expect(() => hashJson(jsonValue)).toThrow(
+ 'The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined',
+ );
+ });
+
+ it("should test hashJson( mock-parameters.jsonValue 8 )", () => {
+ const jsonValue: Parameters[0] = { valid: true };
+ const __expectedResult: ReturnType =
+ "8daf09a6fc31937457dd77e9c25ce4b21349d605b561a8c5d557841bf964c9a0";
+ expect(hashJson(jsonValue)).toEqual(__expectedResult);
+ });
+
+ it("should test hashJson( mock-parameters.jsonValue 9 )", () => {
+ const jsonValue: Parameters[0] = {};
+ const __expectedResult: ReturnType =
+ "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a";
+ expect(hashJson(jsonValue)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("normalizeContentForHash", () => {
+ const { normalizeContentForHash } = __testedFile;
+ // content: string
+
+ it("should test normalizeContentForHash( mock-parameters.content 1 )", () => {
+ const content: Parameters[0] = " \n ";
+ const __expectedResult: ReturnType = "";
+ expect(normalizeContentForHash(content)).toEqual(__expectedResult);
+ });
+
+ it("should test normalizeContentForHash( mock-parameters.content 2 )", () => {
+ const content: Parameters[0] = " \r\n ";
+ const __expectedResult: ReturnType = "";
+ expect(normalizeContentForHash(content)).toEqual(__expectedResult);
+ });
+
+ it("should test normalizeContentForHash( mock-parameters.content 3 )", () => {
+ const content: Parameters[0] = "";
+ const __expectedResult: ReturnType = "";
+ expect(normalizeContentForHash(content)).toEqual(__expectedResult);
+ });
+
+ it("should test normalizeContentForHash( mock-parameters.content 4 )", () => {
+ const content: Parameters[0] = "\r\n";
+ const __expectedResult: ReturnType = "";
+ expect(normalizeContentForHash(content)).toEqual(__expectedResult);
+ });
+
+ it("should test normalizeContentForHash( mock-parameters.content 5 )", () => {
+ const content: Parameters[0] = "\r\nabc";
+ const __expectedResult: ReturnType = "abc";
+ expect(normalizeContentForHash(content)).toEqual(__expectedResult);
+ });
+
+ it("should test normalizeContentForHash( mock-parameters.content 6 )", () => {
+ const content: Parameters[0] = "abc";
+ const __expectedResult: ReturnType = "abc";
+ expect(normalizeContentForHash(content)).toEqual(__expectedResult);
+ });
+
+ it("should test normalizeContentForHash( mock-parameters.content 7 )", () => {
+ const content: Parameters[0] = "abc\r\n pqr \r\nxyz";
+ const __expectedResult: ReturnType = "abc\n pqr \nxyz";
+ expect(normalizeContentForHash(content)).toEqual(__expectedResult);
+ });
+
+ it("should test normalizeContentForHash( mock-parameters.content 8 )", () => {
+ const content: Parameters[0] = "abc\r\n";
+ const __expectedResult: ReturnType = "abc";
+ expect(normalizeContentForHash(content)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("extractTaggedBlock", () => {
+ const { extractTaggedBlock } = __testedFile;
+ // promptText: string
+ // tag: "instructions" | "content"
+
+ it("should test extractTaggedBlock( mock-parameters.promptText 1, mock-parameters.tag 1 )", () => {
+ const promptText: Parameters[0] = " Do this ";
+ const tag: Parameters[1] = "instructions";
+ const __expectedResult: ReturnType = "Do this";
+ expect(extractTaggedBlock(promptText, tag)).toEqual(__expectedResult);
+ });
+
+ it("should test extractTaggedBlock( mock-parameters.promptText 2, mock-parameters.tag 1 )", () => {
+ const promptText: Parameters[0] = "";
+ const tag: Parameters[1] = "instructions";
+ const __expectedResult: ReturnType = null;
+ expect(extractTaggedBlock(promptText, tag)).toEqual(__expectedResult);
+ });
+
+ it("should test extractTaggedBlock( mock-parameters.promptText 3, mock-parameters.tag 1 )", () => {
+ const promptText: Parameters[0] = "";
+ const tag: Parameters[1] = "instructions";
+ const __expectedResult: ReturnType = null;
+ expect(extractTaggedBlock(promptText, tag)).toEqual(__expectedResult);
+ });
+
+ it("should test extractTaggedBlock( mock-parameters.promptText 4, mock-parameters.tag 1 )", () => {
+ const promptText: Parameters[0] = "";
+ const tag: Parameters[1] = "instructions";
+ const __expectedResult: ReturnType = "";
+ expect(extractTaggedBlock(promptText, tag)).toEqual(__expectedResult);
+ });
+
+ it("[bug] Nested Tags", () => {
+ const promptText: Parameters[0] =
+ "ABC";
+ const tag: Parameters[1] = "instructions";
+ const __expectedResult: ReturnType = "AB";
+ expect(extractTaggedBlock(promptText, tag)).toEqual(__expectedResult);
+ });
+
+ it("should test extractTaggedBlock( mock-parameters.promptText 6, mock-parameters.tag 1 )", () => {
+ const promptText: Parameters[0] = "Do this";
+ const tag: Parameters[1] = "instructions";
+ const __expectedResult: ReturnType = "Do this";
+ expect(extractTaggedBlock(promptText, tag)).toEqual(__expectedResult);
+ });
+
+ it("should test extractTaggedBlock( mock-parameters.promptText 7, mock-parameters.tag 1 )", () => {
+ const promptText: Parameters[0] = "Do this";
+ const tag: Parameters[1] = "instructions";
+ const __expectedResult: ReturnType = "Do this";
+ expect(extractTaggedBlock(promptText, tag)).toEqual(__expectedResult);
+ });
+
+ it("should test extractTaggedBlock( mock-parameters.promptText 8, mock-parameters.tag 1 )", () => {
+ const promptText: Parameters[0] =
+ "Do thisText";
+ const tag: Parameters[1] = "instructions";
+ const __expectedResult: ReturnType = "Do this";
+ expect(extractTaggedBlock(promptText, tag)).toEqual(__expectedResult);
+ });
+
+ it("should test extractTaggedBlock( mock-parameters.promptText 9, mock-parameters.tag 1 )", () => {
+ const promptText: Parameters[0] =
+ "Do thisDo that";
+ const tag: Parameters[1] = "instructions";
+ const __expectedResult: ReturnType = "Do this";
+ expect(extractTaggedBlock(promptText, tag)).toEqual(__expectedResult);
+ });
+
+ it("should test extractTaggedBlock( mock-parameters.promptText 10, mock-parameters.tag 1 )", () => {
+ const promptText: Parameters[0] = "Part 1\nPart 2";
+ const tag: Parameters[1] = "instructions";
+ const __expectedResult: ReturnType = "Part 1\nPart 2";
+ expect(extractTaggedBlock(promptText, tag)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("buildPromptHash", () => {
+ const { buildPromptHash } = __testedFile;
+ // prompt: string
+
+ it("should test buildPromptHash( mock-parameters.prompt 1 )", () => {
+ const prompt: Parameters[0] = " Do this ";
+ const __expectedResult: ReturnType =
+ "1d75e222aec1fbd4e394723435858f4f40bab950a79ee6c3d5ae048ac77aec70";
+ expect(buildPromptHash(prompt)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptHash( mock-parameters.prompt 2 )", () => {
+ const prompt: Parameters[0] = "";
+ const __expectedResult: ReturnType =
+ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
+ expect(buildPromptHash(prompt)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptHash( mock-parameters.prompt 3 )", () => {
+ const prompt: Parameters[0] = " Do this ";
+ const __expectedResult: ReturnType =
+ "1d75e222aec1fbd4e394723435858f4f40bab950a79ee6c3d5ae048ac77aec70";
+ expect(buildPromptHash(prompt)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptHash( mock-parameters.prompt 4 )", () => {
+ const prompt: Parameters[0] = "Do this";
+ const __expectedResult: ReturnType =
+ "1d75e222aec1fbd4e394723435858f4f40bab950a79ee6c3d5ae048ac77aec70";
+ expect(buildPromptHash(prompt)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptHash( mock-parameters.prompt 5 )", () => {
+ const prompt: Parameters[0] = "A Do this B";
+ const __expectedResult: ReturnType =
+ "1d75e222aec1fbd4e394723435858f4f40bab950a79ee6c3d5ae048ac77aec70";
+ expect(buildPromptHash(prompt)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptHash( mock-parameters.prompt 6 )", () => {
+ const prompt: Parameters[0] = "Do this";
+ const __expectedResult: ReturnType =
+ "1d75e222aec1fbd4e394723435858f4f40bab950a79ee6c3d5ae048ac77aec70";
+ expect(buildPromptHash(prompt)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptHash( mock-parameters.prompt 7 )", () => {
+ const prompt: Parameters[0] = "abc";
+ const __expectedResult: ReturnType =
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
+ expect(buildPromptHash(prompt)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("buildPromptContentHash", () => {
+ const { buildPromptContentHash } = __testedFile;
+ // promptFallbackContent: { prompt: string; fallbackContent?: string; }
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 1 )", () => {
+ const promptFallbackContent: Parameters[0] = { prompt: "", fallbackContent: "" };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 2 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "",
+ fallbackContent: "abc",
+ };
+ const __expectedResult: ReturnType =
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 3 )", () => {
+ const promptFallbackContent: Parameters[0] = { prompt: "", fallbackContent: null };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 4 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "",
+ fallbackContent: undefined,
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 5 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "",
+ fallbackContent: "",
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 6 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "",
+ fallbackContent: "abc",
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 7 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "",
+ fallbackContent: null,
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 8 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "",
+ fallbackContent: undefined,
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 9 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "Text",
+ fallbackContent: "",
+ };
+ const __expectedResult: ReturnType =
+ "71988c4d8e0803ba4519f0b2864c1331c14a1890bf8694e251379177bfedb5c3";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 10 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "Text",
+ fallbackContent: "abc",
+ };
+ const __expectedResult: ReturnType =
+ "71988c4d8e0803ba4519f0b2864c1331c14a1890bf8694e251379177bfedb5c3";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 11 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "Text",
+ fallbackContent: null,
+ };
+ const __expectedResult: ReturnType =
+ "71988c4d8e0803ba4519f0b2864c1331c14a1890bf8694e251379177bfedb5c3";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 12 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "Text",
+ fallbackContent: undefined,
+ };
+ const __expectedResult: ReturnType =
+ "71988c4d8e0803ba4519f0b2864c1331c14a1890bf8694e251379177bfedb5c3";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 13 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "ABC",
+ fallbackContent: "",
+ };
+ const __expectedResult: ReturnType =
+ "df7e70e5021544f4834bbee64a9e3789febc4be81470df629cad6ddb03320a5c";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 14 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "ABC",
+ fallbackContent: "abc",
+ };
+ const __expectedResult: ReturnType =
+ "df7e70e5021544f4834bbee64a9e3789febc4be81470df629cad6ddb03320a5c";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 15 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "ABC",
+ fallbackContent: null,
+ };
+ const __expectedResult: ReturnType =
+ "df7e70e5021544f4834bbee64a9e3789febc4be81470df629cad6ddb03320a5c";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 16 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "ABC",
+ fallbackContent: undefined,
+ };
+ const __expectedResult: ReturnType =
+ "df7e70e5021544f4834bbee64a9e3789febc4be81470df629cad6ddb03320a5c";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 17 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "AB",
+ fallbackContent: "",
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 18 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "AB",
+ fallbackContent: "abc",
+ };
+ const __expectedResult: ReturnType =
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 19 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "AB",
+ fallbackContent: null,
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 20 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "AB",
+ fallbackContent: undefined,
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 21 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "No tags here",
+ fallbackContent: "",
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 22 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "No tags here",
+ fallbackContent: "abc",
+ };
+ const __expectedResult: ReturnType =
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 23 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "No tags here",
+ fallbackContent: null,
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+
+ it("should test buildPromptContentHash( mock-parameters.promptFallbackContent 24 )", () => {
+ const promptFallbackContent: Parameters[0] = {
+ prompt: "No tags here",
+ fallbackContent: undefined,
+ };
+ const __expectedResult: ReturnType = null;
+ expect(buildPromptContentHash(promptFallbackContent)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("buildLengthKey", () => {
+ const { buildLengthKey } = __testedFile;
+ // lengthArg: LengthArg
+
+ it("should test buildLengthKey( mock-parameters.lengthArg 1 )", () => {
+ const lengthArg: Parameters[0] = { kind: "chars", maxCharacters: 10 };
+ const __expectedResult: ReturnType = "chars:10";
+ expect(buildLengthKey(lengthArg)).toEqual(__expectedResult);
+ });
+
+ it("should test buildLengthKey( mock-parameters.lengthArg 2 )", () => {
+ const lengthArg: Parameters[0] = { kind: "preset", preset: "medium" };
+ const __expectedResult: ReturnType = "preset:medium";
+ expect(buildLengthKey(lengthArg)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("buildLanguageKey", () => {
+ const { buildLanguageKey } = __testedFile;
+ // outputLanguage: OutputLanguage
+
+ it("should test buildLanguageKey( mock-parameters.outputLanguage 1 )", () => {
+ const outputLanguage: Parameters[0] = { kind: "auto" };
+ const __expectedResult: ReturnType = "auto";
+ expect(buildLanguageKey(outputLanguage)).toEqual(__expectedResult);
+ });
+
+ it("should test buildLanguageKey( mock-parameters.outputLanguage 2 )", () => {
+ const outputLanguage: Parameters[0] = { kind: "fixed", tag: "TAG", label: "English" };
+ const __expectedResult: ReturnType = "TAG";
+ expect(buildLanguageKey(outputLanguage)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("buildExtractCacheKeyValue", () => {
+ const { buildExtractCacheKeyValue } = __testedFile;
+ // cacheKey: { url: string; options: Record; formatVersion: number; }
+
+ it("should test buildExtractCacheKeyValue( mock-parameters.cacheKey 1 )", () => {
+ const cacheKey: Parameters[0] = {
+ url: "https://localhost",
+ options: {},
+ formatVersion: 1,
+ };
+ const __expectedResult: ReturnType =
+ "0b8b6f834c5f41ded2d14c4aa6e3e57e836985335da96f6e6ceb4863b020b6e8";
+ expect(buildExtractCacheKeyValue(cacheKey)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("buildSummaryCacheKeyValue", () => {
+ const { buildSummaryCacheKeyValue } = __testedFile;
+ // summaryCacheKey: { contentHash: string; promptHash: string; model: string; lengthKey: string; languageKey: string; formatVersion: number; }
+
+ it("should test buildSummaryCacheKeyValue( mock-parameters.summaryCacheKey 1 )", () => {
+ const summaryCacheKey: Parameters[0] = {
+ contentHash: "1",
+ promptHash: "2",
+ model: "model",
+ lengthKey: "1",
+ languageKey: "English",
+ formatVersion: 1,
+ };
+ const __expectedResult: ReturnType =
+ "ab473a87b6e86f5630671862a4c4e933ca7a9f7dfdc6e8dde8e0c1692dd5ab64";
+ expect(buildSummaryCacheKeyValue(summaryCacheKey)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("buildSlidesCacheKeyValue", () => {
+ const { buildSlidesCacheKeyValue } = __testedFile;
+ // slidesCacheKey: { url: string; settings: { ocr: boolean; outputDir: string; sceneThreshold: number; autoTuneThreshold: boolean; maxSlides: number; minDurationSeconds: number; }; formatVersion: number; }
+
+ it("should test buildSlidesCacheKeyValue( mock-parameters.slidesCacheKey 1 )", () => {
+ const slidesCacheKey: Parameters[0] = {
+ url: "url",
+ settings: {
+ ocr: true,
+ outputDir: ".",
+ sceneThreshold: 0,
+ autoTuneThreshold: true,
+ maxSlides: 1,
+ minDurationSeconds: 1,
+ },
+ formatVersion: 1,
+ };
+ const __expectedResult: ReturnType =
+ "baa408bb0e376b3b2a100b575bfaf8bc26f539850cf3cf187ef810a95a40a600";
+ expect(buildSlidesCacheKeyValue(slidesCacheKey)).toEqual(__expectedResult);
+ });
+ });
+
+ describe("buildTranscriptCacheKeyValue", () => {
+ const { buildTranscriptCacheKeyValue } = __testedFile;
+ // transcriptCacheKey: { url: string; namespace: string; formatVersion: number; fileMtime?: number; }
+
+ it("should test buildTranscriptCacheKeyValue( mock-parameters.transcriptCacheKey 1 )", () => {
+ const transcriptCacheKey: Parameters[0] = {
+ url: "url",
+ namespace: "ns",
+ formatVersion: 1,
+ fileMtime: null,
+ };
+ const __expectedResult: ReturnType =
+ "26243737dfcd6603f3823f35577d9a049ec328d3aaaf4349f67148f3bfc62332";
+ expect(buildTranscriptCacheKeyValue(transcriptCacheKey)).toEqual(__expectedResult);
+ });
+
+ it("should test buildTranscriptCacheKeyValue( mock-parameters.transcriptCacheKey 2 )", () => {
+ const transcriptCacheKey: Parameters[0] = {
+ url: "url",
+ namespace: "ns",
+ formatVersion: 1,
+ fileMtime: undefined,
+ };
+ const __expectedResult: ReturnType =
+ "26243737dfcd6603f3823f35577d9a049ec328d3aaaf4349f67148f3bfc62332";
+ expect(buildTranscriptCacheKeyValue(transcriptCacheKey)).toEqual(__expectedResult);
+ });
+ });
+});
+
+// 3TG (https://3tg.dev) created 70 tests in 2584 ms (36.914 ms per generated test) @ 2026-03-17T13:16:53.261Z