TS and Python: pin the refusal text (v3 named, ASCII digits only); TS comments say a zero-byte file is refused
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9a251fe60c
commit
7b815e1ca8
3 changed files with 26 additions and 3 deletions
|
|
@ -1383,6 +1383,8 @@ class CultCacheTests(unittest.TestCase):
|
|||
("cultcache.store.v12", "'cultcache.store.v12'"),
|
||||
("cultcache.store.SECRET", "an unrecognised cultcache.store.* header of 22 bytes"),
|
||||
("cultcache.store.v", "an unrecognised cultcache.store.* header of 17 bytes"),
|
||||
# Digits are ASCII only: two Arabic-Indic digits are four bytes and are not the known shape.
|
||||
("cultcache.store.v١٢", "an unrecognised cultcache.store.* header of 21 bytes"),
|
||||
):
|
||||
path.write_bytes(msgpack.packb([header, [], []], use_bin_type=True))
|
||||
with self.assertRaises(ValueError) as caught:
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ export class SingleFileMessagePackBackingStore implements CacheBackingStore {
|
|||
}
|
||||
|
||||
// A flush of the whole store writes the header the file on disk carries, read now: a file marked for element ids
|
||||
// stays marked, and one that is not (or is gone, empty or legacy) is written unmarked. The file is read by the same
|
||||
// stays marked, and one that is not (or is gone or legacy) is written unmarked. The file is read by the same
|
||||
// reader as `pullAll`, so one it would refuse (not exactly one store, a variant, a body it cannot decode) is refused
|
||||
// and left as it is.
|
||||
try {
|
||||
|
|
@ -101,8 +101,9 @@ export class SingleFileMessagePackBackingStore implements CacheBackingStore {
|
|||
});
|
||||
}
|
||||
|
||||
// The one reader of the store file, asked by open, push, delete and flush alike. A file that is gone or zero bytes is an
|
||||
// empty unmarked store; anything else must decode completely or the read throws StoreUnreadableError.
|
||||
// The one reader of the store file, asked by open, push, delete and flush alike. A file that is gone is an
|
||||
// empty unmarked store; a zero-byte file is not a store and is refused. Anything else must decode completely
|
||||
// or the read throws StoreUnreadableError.
|
||||
async #readDisk(): Promise<DiskStore> {
|
||||
// An empty file is not a store, since no CultCache writer leaves one, so it is decoded and refused.
|
||||
// Only a read that finds nothing at the path is an empty store.
|
||||
|
|
|
|||
|
|
@ -1999,6 +1999,26 @@ test("SingleFileMessagePackBackingStore refusals say what was found without blam
|
|||
);
|
||||
});
|
||||
|
||||
test("SingleFileMessagePackBackingStore refusal says what was found and names every format it reads", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "cultcache-refusal-"));
|
||||
const file = join(dir, "store.cc");
|
||||
const reads = 'it reads "cultcache.store.v1" and "cultcache.store.v3" only.';
|
||||
for (const [header, found] of [
|
||||
["cultcache.store.v12", '"cultcache.store.v12"'],
|
||||
["cultcache.store.SECRET", "an unrecognised cultcache.store.* header of 22 bytes"],
|
||||
["cultcache.store.v", "an unrecognised cultcache.store.* header of 17 bytes"],
|
||||
// Digits are ASCII only: two Arabic-Indic digits are four bytes and are not the known shape.
|
||||
["cultcache.store.v١٢", "an unrecognised cultcache.store.* header of 21 bytes"],
|
||||
] as const) {
|
||||
await writeFile(file, encode([header, [], []]));
|
||||
await assert.rejects(
|
||||
() => new SingleFileMessagePackBackingStore(file).pullAll(),
|
||||
(error: Error) => error.message.includes(`CultCache store format ${found} is not one this runtime reads; ${reads}`),
|
||||
header,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("SingleFileMessagePackBackingStore reads only a missing store as empty", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "cultcache-absent-"));
|
||||
assert.deepEqual(await new SingleFileMessagePackBackingStore(join(dir, "store.cc")).pullAll(), []);
|
||||
|
|
|
|||
Loading…
Reference in a new issue