33 lines
2.6 KiB
Python
33 lines
2.6 KiB
Python
# mutate.py <id>: apply one named mutant to the candidate (exact text, must match once). Run from the tree root.
|
|
import sys
|
|
P, R, T, X = "packages/runs/src/paths.mjs", "packages/runs/src/runs.mjs", "packages/runs/src/state.mjs", "scripts/mosaic-task.mjs"
|
|
M = {
|
|
"D01": [(X, " if (!isRunId(runId)) {\n fail(4, `invalid run id", " if (false) {\n fail(4, `invalid run id")],
|
|
"D03": [(P, " } catch {\n return null;\n }\n}", " } catch (error) {\n if (error instanceof RunsError) throw error;\n return null;\n }\n}")],
|
|
"D04": [(R, " if (resolveInside(dataRoot, RUNS_DIRNAME) === null) return null;\n", "")],
|
|
"D05": [(T, "entries.slice(-last)", "entries.slice(0, last)")],
|
|
"D06": [(T, ' if (entry.note !== undefined && typeof entry.note !== "string") return null;\n', "")],
|
|
"D07": [(R, " if (isMissing(error)) return [];\n throw new RunsError(`cannot read ${root}", " return [];\n throw new RunsError(`cannot read ${root}")],
|
|
"D08": [(T, " } catch (error) {\n throw new RunsError(`cannot read ${file}", " } catch (error) {\n return null;\n throw new RunsError(`cannot read ${file}")],
|
|
"D09": [(T, "if (!POINTER_KEYS.includes(key))", "if (false)")],
|
|
"D10": [(P, 'return relative === "" ||', "return false ||")],
|
|
"D11": [(X, "if (error instanceof RunsError) fail(error.exitCode, error.message);\n throw error;\n }\n}\n\nfunction listRuns", "if (false) fail(error.exitCode, error.message);\n throw error;\n }\n}\n\nfunction listRuns")],
|
|
"D13": [(R, " if (isMissing(error)) return null;\n throw new RunsError(`cannot read ${dir}", " throw new RunsError(`cannot read ${dir}")],
|
|
"D14": [(P, "real = fs.realpathSync(target);", "real = path.resolve(target);")],
|
|
"D15": [(P, "root = fs.realpathSync(dataRoot);", "root = path.resolve(dataRoot);")],
|
|
"D16": [(R, "{0,63}$/", "{0,64}$/")],
|
|
"D17": [(R, ' result: readJsonObject(dataRoot, RUNS_DIRNAME, runId, "result.json"),', ' result: readRunDocument(dataRoot, runId, "result.json"),')],
|
|
"D18": [(T, 'if (line.trim() === "") continue;', 'if (line === "") continue;')],
|
|
"D19": [(R, " requireRunId(runId);\n if (!RUN_DOCUMENTS", " if (!RUN_DOCUMENTS")],
|
|
"D20": [(R, 'filter((name) => name.startsWith("r-")).sort()', "filter(isRunId).sort()")],
|
|
"D21": [(T, "if (pointer.pointerVersion !== 1)", "if (false)")],
|
|
"D22": [(T, '["at", "event", "release", "imageTag"].every', '["at", "event", "release"].every')],
|
|
"D23": [(T, "last < 1)", "last < 0)")],
|
|
}
|
|
for f, old, new in M[sys.argv[1]]:
|
|
s = open(f).read()
|
|
n = s.count(old)
|
|
if n != 1: sys.exit(f"{sys.argv[1]}: {n} matches in {f}")
|
|
open(f, "w").write(s.replace(old, new))
|
|
print(sys.argv[1], "applied")
|