Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/fork/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ Only the person can change it; agents cannot. A save that is on without all four
push step's name (or names one `claim`, `renew` or `release`), names a program by anything but its
full path on the server's OS, or has a field this build does not know is refused. A hand-edited
value that is not valid, or has a field this build does not know (a newer build's limit, a typo),
reads as off (with a warning in the server log), and the next save of any setting writes the default
in its place. So after moving back to an older build, copy the playtest value first: the older
reads as off (with a warning in the server log that names what is wrong, such as the unknown
field), and the next save of any setting writes the default in its place. So after moving back to an older build, copy the playtest value first: the older
build's next save replaces a newer build's value. Other fields: how often a claim is renewed (`renewMinutes`), when an idle
session ends (`idleMinutes`) and the longest session (`maxHours`).

Expand Down
33 changes: 17 additions & 16 deletions fork-kit/cleaner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ stays, each reads the same bytes as before, and the disk holds them once. Withou
| `dedupe.folders[].path` | required | a folder; files at any depth in it are looked at |
| `dedupe.folders[].days` | required | days without a change (7 or more): newer files are not looked at |
| `dedupe.folders[].layered` | false | the folder may be on a filesystem that is not local (as compress-cold) |
| `dedupe.writtenInPlace` | required | more name patterns (no `/`) never linked: one program's own kinds |
| `dedupe.writtenInPlace` | none | more name patterns (no `/`) never linked: one program's own kinds |

**The risk it takes: read this before you name a folder.** Names of one hard-linked file are one file, so any
write **into** one name changes every name, and the other names' old bytes are gone. Most ways of writing a file do
Expand All @@ -634,7 +634,8 @@ images, no working copies. The rule refuses the kinds it knows are written in pl
`*.log`, `*.log.*`, `*.jsonl`, `*.ndjson`, `*.journal`, `*.pid`; disk images `*.qcow2`, `*.img`, `*.raw`, `*.vmdk`,
`*.vdi`, `*.vhd`, `*.vhdx`; swap `*.swp`, `*.swap`; mail boxes `mbox`, `*.mbox`; partial downloads a client resumes
in place `*.part`, `*.crdownload`, `*.partial`, `*.!qb`), plus the name patterns in `dedupe.writtenInPlace` (one
program's own kinds, such as a game's save files; `[]` when the folders hold none), but such a list can never be
program's own kinds, such as a game's save files; `[]` when the folders hold none: while `dedupe.folders` names a
folder and this key is missing, the rule links nothing and the run exits 1, see below), but such a list can never be
complete. Every plan and run that links says it again in one line (`dedupe: names of one file share every later
write ...`). On btrfs or XFS a tool that shares blocks with a reflink (`FIDEDUPERANGE`) is the
safer choice: later writes do not reach the other copies. This rule makes hard links because the hosts it was made
Expand Down Expand Up @@ -713,11 +714,12 @@ the rename)`. The report has a class
- **it stops half-way:** the duplicate is either as it was or a name of the kept file, never gone. Killed before
the new name: nothing changed. Killed between the new name and the rename: the duplicate is as it was and the
part `.<name>.<8 hex>.cleaner-link` stays; the next run removes that part (only while it is one the cleaner wrote
down and still a name of a file with other names) and links again. Killed right after a link or rename, before its
inode time was written down: the kept file looks changed and waits its `days`, then the run goes on. Killed while
the cache is written: the old cache stays, and the list of its own steps still holds what it did. A part that is
the last name of its bytes is kept and named (`part without its file`). A failed rename removes the part and keeps
the duplicate. No entry goes into the journal of half deletes: there is nothing half gone.
down and still a name of a file with other names) and links again. While `dedupe.writtenInPlace` is missing the
rule reads no folder, so the part stays (one more name of the kept file) until the key is added. Killed right
after a link or rename, before its inode time was written down: the kept file looks changed and waits its `days`,
then the run goes on. Killed while the cache is written: the old cache stays, and the list of its own steps still
holds what it did. A part that is the last name of its bytes is kept and named (`part without its file`). A
failed rename removes the part and keeps the duplicate. No entry goes into the journal of half deletes: there is nothing half gone.
- **a file changes or is opened:** while the plan reads it: kept as `changed`. Between the plan and the run, or
while it is compared or linked: refused or failed, both files stay as they are (the next run sees other bytes and
joins nothing). A kept file replaced, or given, losing or moving a name, after the plan: refused.
Expand All @@ -730,13 +732,12 @@ the rename)`. The report has a class
links nothing. Each folder is kept with `could not read: dedupe.writtenInPlace is missing ...` and every run
exits 1 until the key is there; the other rules run as usual. `[]` is the owner's word that no program writes
its own kinds in place in these folders.
- **the cleaner is older than the machine file:** an older cleaner refuses the unknown `dedupe` key and every daily
run exits 2. Install this cleaner on a machine first, then add the key.
- **upgrading a machine whose `dedupe` section has no `writtenInPlace`:** add the key first (the kinds a program
there writes in place, or `[]`), then install this cleaner. Until the new cleaner is in, the older one refuses
the machine file (`unknown key 'writtenInPlace'`) and every rule stops, every daily run exits 2, nothing is
touched. The other order is safe too, only noisier: the new cleaner links nothing and exits 1 until the key is
added.
- **upgrading a machine:** install this cleaner first, then add `dedupe` or, to a `dedupe` section an older cleaner
read, `writtenInPlace` (the kinds a program there writes in place, or `[]`). In between, the rule does nothing
(no `dedupe`) or links nothing and exits 1 (no `writtenInPlace`, above); the other rules run. The other order
stops more: a cleaner older than the machine file refuses the unknown key (`unknown key 'dedupe'` or
`unknown key 'writtenInPlace'`), so every rule stops and every daily run exits 2, touching nothing, until this
cleaner is in.

## The machine file

Expand Down Expand Up @@ -822,8 +823,8 @@ floor, a root folder that is `/`, the home folder or a folder above it: the comm
exits 2 and does nothing.

Every key can only pick what a rule looks at, raise a floor, or keep more (`KEY_KINDS` in `config.py`; a test
fails for a key that is not placed there). Two keys free more. `layered` (a cold or dedupe folder may be on a
filesystem that is not local: an overlay, FUSE or a share) is a yes or no, false by default. `regenerable` takes plain folder names
fails for a key that is not placed there). Two keys take a refusal away. `layered` (a cold or dedupe folder may be
on a filesystem that is not local: an overlay, FUSE or a share) is a yes or no, false by default. `regenerable` takes plain folder names
only: no `/` and no wildcard, so `["*"]` is refused and can never take the `ignored files` refusal away. A name
frees an ignored folder of that name (and what is in it), never a file, and never a credential-looking name.

Expand Down
5 changes: 3 additions & 2 deletions fork-kit/cleaner/lib/cleaner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ def _github(value):
'compressCold': 'picks', 'compressCold.folders': 'picks', 'compressCold.keepFreeGB': 'floor',
'folders.path': 'picks', 'folders.days': 'floor', 'folders.layered': 'loosens',
# dedupe deletes no content either (every name keeps its bytes and metadata); its folders never are or hold a
# must-keep path, and every refusal holds in them (dedupe.py).
'dedupe': 'picks', 'dedupe.folders': 'picks', 'dedupe.writtenInPlace': 'keeps more',
# must-keep path, and every refusal holds in them (dedupe.py). writtenInPlace picks too: its patterns keep more,
# but missing it links nothing and `[]` turns linking on.
'dedupe': 'picks', 'dedupe.folders': 'picks', 'dedupe.writtenInPlace': 'picks',
# agentScratch: on, its folder and its days pick what it looks at. keepFirst only adds a copy before a delete:
# more patterns copy more; maxFileBytes has a floor; a session with more than maxSessionBytes to copy stays
# whole, so the cap picks which sessions the rule may take at all (every refusal still holds for them). The
Expand Down
5 changes: 3 additions & 2 deletions fork-kit/cleaner/lib/cleaner/dedupe.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
the kept file, never nothing.

So a run killed between the two leaves the duplicate as it was and a part that is one more name of the kept file;
the next run removes that part (a name whose content another name still holds) and links again. A part whose other
names are all gone holds the only copy of its content and stays (named in the plan).
the next run that reads the folders (not one without `dedupe.writtenInPlace`) removes that part (a name whose
content another name still holds) and links again. A part whose other names are all gone holds the only copy of
its content and stays (named in the plan).

What it never takes: links (never followed), other filesystems and mount points (a hard link cannot cross one
either), other owners' files, credential and lock names, must-keep names, folders with a KEEP file and git folders,
Expand Down
9 changes: 6 additions & 3 deletions fork-kit/cleaner/tests/dedupe.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ def test_killed_between_the_link_and_the_rename_the_next_run_finishes(self):
self.assertRegex(os.path.basename(part), r'^\.b\.bin\.[0-9a-f]{8}\.cleaner-link$')
self.assertEqual((self.ino(b), self.read(b)), (dup, body())) # the duplicate as it was
self.assertEqual(self.ino(part), self.ino(a)) # one more name of the kept file
# Without `dedupe.writtenInPlace` the rule reads no folder: the part stays until the key is back (README).
code, lines = self.run_cleaner(self.dd_cfg(in_place=None))
self.assertEqual((code, self.files()), (1, names), lines)
plan = self.plan(self.dd_cfg())
self.assertEqual(self.items(plan, 'link-part'), [part])
self.assertEqual(self.items(plan), [b])
Expand Down Expand Up @@ -722,14 +725,14 @@ def test_more_kinds_written_in_place(self):

def test_the_machine_file_adds_kinds_written_in_place(self):
"""A program's own kinds (a game's save files) are named in the machine file, not in the code."""
a, b = self.put('r.0.0.MCA', days=50), self.put('r.0.1.mca')
a, b = self.put('slot1.SAV', days=50), self.put('slot2.sav')
c, d = self.put('x.bin', days=50), self.put('y.bin')
kinds = lambda value: self.dd_cfg(in_place=value)
plan = self.plan(kinds(['*.mca', 'world.dat']))
plan = self.plan(kinds(['*.sav', 'world.dat']))
for path in (a, b):
self.assertKept(plan, path, 'written in place')
self.assertEqual(self.items(plan), [d])
for bad in (['saves/*.mca'], [''], ['..'], [5], '*.mca'):
for bad in (['saves/*.sav'], [''], ['..'], [5], '*.sav'):
with self.subTest(bad=bad), self.assertRaises(machine_file.MachineFileError):
kinds(bad)

Expand Down
21 changes: 17 additions & 4 deletions packages/contracts/src/playtest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,27 @@ describe("playtest settings in the settings file", () => {
expect(settings.projectSettingsOverrides[PROJECT]?.playtest).toEqual(DEFAULT_PLAYTEST_SETTINGS);
});

it.effect("warns when it drops a bad value", () =>
it.effect("warns when it drops a bad value, naming an unknown field", () =>
Effect.gen(function* () {
const logged: Array<unknown> = [];
const logger = Logger.make(({ message }) => logged.push(message));
yield* decodeFileEffect(without("claim")).pipe(
Effect.provide(Logger.layer([logger], { mergeWithExisting: false })),
);
const drop = (bad: unknown) =>
decodeFileEffect(bad).pipe(
Effect.provide(Logger.layer([logger], { mergeWithExisting: false })),
);
yield* drop(without("claim"));
expect(JSON.stringify(logged)).toContain("invalid playtest settings read as off");
yield* drop({ ...ADAPTER, claim: { ...ADAPTER.claim, maxRuns: 1 } });
expect(String(logged.at(-1))).toContain(
'Expected no excess property at ["claim"]["maxRuns"]',
);
expect(String(logged.at(-1))).not.toMatch(/\s{2}/);
yield* drop({
...ADAPTER,
claim: step(["game", "--token=SECRETVALUE"]),
});
expect(String(logged.at(-1))).toContain("invalid playtest settings read as off");
expect(String(logged.at(-1))).not.toContain("SECRETVALUE");
}),
);

Expand Down
15 changes: 10 additions & 5 deletions packages/contracts/src/playtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* follows (environment, exit codes); docs/fork/playtest.md. Off by default.
*/
import * as Effect from "effect/Effect";
import * as Result from "effect/Result";
import * as Schema from "effect/Schema";
import * as SchemaTransformation from "effect/SchemaTransformation";

Expand Down Expand Up @@ -139,10 +140,13 @@ export type PlaytestSettings = typeof PlaytestSettings.Type;
/** Off, no steps, the default limits. */
export const DEFAULT_PLAYTEST_SETTINGS: PlaytestSettings = Schema.decodeSync(PlaytestSettings)({});

const decodePlaytestSettingsOption = Schema.decodeUnknownOption(PlaytestSettings);
const decodePlaytestSettingsResult = Schema.decodeUnknownResult(PlaytestSettings);
/** Also refuses an unknown field, nested ones too: it may be a newer build's limit. */
const isStrictPlaytestSettings = (raw: unknown) =>
decodePlaytestSettingsOption(raw, { onExcessProperty: "error" })._tag === "Some";
const strictPlaytestSettingsProblem = (raw: unknown): string | undefined => {
const decoded = decodePlaytestSettingsResult(raw, { onExcessProperty: "error" });
return Result.isFailure(decoded) ? decoded.failure.message : undefined;
};
const isStrictPlaytestSettings = (raw: unknown) => strictPlaytestSettingsProblem(raw) === undefined;

/** A save's value: refused when bad, also for a field this build does not know (never dropped). */
export const PlaytestSettingsPatch = Schema.Unknown.check(
Expand Down Expand Up @@ -173,11 +177,12 @@ export const PlaytestSettingsFromSettingsFile = Schema.Unknown.pipe(
PlaytestSettings,
SchemaTransformation.transformEffect({
decode: Effect.fn("PlaytestSettingsFromSettingsFile.decode")(function* (raw: unknown) {
if (isStrictPlaytestSettings(raw)) {
const problem = strictPlaytestSettingsProblem(raw);
if (problem === undefined) {
return raw as typeof PlaytestSettings.Encoded;
}
yield* Effect.logWarning(
"settings: invalid playtest settings read as off; the next settings save replaces them",
`settings: invalid playtest settings read as off (${problem.replace(/\s+/g, " ").trim()}); the next settings save replaces them`,
);
return {};
}),
Expand Down
Loading