test: close audit cleanup findings

This commit is contained in:
Federico Jaramillo Martinez
2026-07-03 21:40:36 +02:00
parent 10efb7f221
commit 8511604e83
7 changed files with 38 additions and 38 deletions
+22 -4
View File
@@ -37,10 +37,8 @@ describe("pi-web-docker documentation", () => {
readRepoFile("docker/pi-web-docker"),
]);
for (const command of PI_WEB_DOCKER_USER_COMMANDS) {
expect(dockerReadme).toContain(`| \`${command}\` |`);
expect(dockerEntrypoint).toContain(command);
}
expect(readDockerCommandMatrix(dockerReadme)).toEqual([...PI_WEB_DOCKER_USER_COMMANDS]);
expect(readEntrypointCommandCases(dockerEntrypoint)).toEqual(new Set(PI_WEB_DOCKER_USER_COMMANDS));
expect(dockerReadme).toContain("`pi-web-docker --dev status`");
expect(dockerReadme).toContain("`./docker/pi-web-docker --dev start`");
@@ -49,6 +47,26 @@ describe("pi-web-docker documentation", () => {
});
});
function readDockerCommandMatrix(dockerReadme: string): string[] {
const commandMatrixSection = dockerReadme.split("### Command matrix\n")[1]?.split("\n### Installer options")[0] ?? "";
return Array.from(commandMatrixSection.matchAll(/^\| `([^`]+)` \|/gm), (match) => {
const command = match[1];
if (command === undefined) throw new Error("Docker command matrix row did not include a command");
return command;
});
}
function readEntrypointCommandCases(dockerEntrypoint: string): Set<string> {
const commandCaseBlock = dockerEntrypoint.slice(dockerEntrypoint.indexOf('case "$command_name" in'));
const commandCases = new Set<string>();
for (const line of commandCaseBlock.split("\n")) {
const match = /^ {2}([a-z][a-z-]*(?:\|[a-z][a-z-]*)*)(?:\|__run-detached)?\)$/.exec(line);
if (match?.[1] === undefined) continue;
for (const command of match[1].split("|")) commandCases.add(command);
}
return commandCases;
}
async function readRepoFile(relativePath: string): Promise<string> {
return await readFile(join(repoRoot, relativePath), "utf8");
}