forked from mtusi2026/mtusi2026lab7
Prepare verified laboratory 7 implementation and evidence
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
bun test v1.4.4 (38afee6c8)
|
||||
|
||||
student-tests/replica-snapshot.test.ts:
|
||||
4 | function fixture() {
|
||||
5 | const commands: string[][] = [], reads: Record<string, number> = {};
|
||||
6 | const state = (service: string): ReplicaState => ({id: (service === "api1" ? "a" : "b").repeat(64), running:true, project:"mtuci-vp7-security",service,started:"2026-11-16T11:00:00Z"});
|
||||
7 | return {commands, reads, state, ports:{
|
||||
8 | inspect: async (service: "api1" | "api2") => {reads[service]=(reads[service]??0)+1;return state(service);},
|
||||
9 | command: async (args:string[]) => {commands.push(args); if (args[1] === "cp") throw Error("DOCKER_CP_TMPFS_NOT_VISIBLE");return aliases[args[2]==="a".repeat(64)?0:1];},
|
||||
^
|
||||
error: DOCKER_CP_TMPFS_NOT_VISIBLE
|
||||
at command (/Users/rey/mtuci/vp/lab7/student-tests/replica-snapshot.test.ts:9:89)
|
||||
at <anonymous> (/Users/rey/mtuci/vp/lab7/scripts/replica-snapshot.ts:21:34)
|
||||
at async <anonymous> (/Users/rey/mtuci/vp/lab7/student-tests/replica-snapshot.test.ts:13:64)
|
||||
(fail) read each current UUID through exec in the verified immutable container, without filesystem copy [2.55ms]
|
||||
14 | expect(actual.api1).toEqual({container:"a".repeat(64),alias:aliases[0]});
|
||||
15 | expect(f.commands).toEqual(["a","b"].map(c=>["docker","exec",c.repeat(64),"/bin/cat","/tmp/messenger-instance-id"]));
|
||||
16 | });
|
||||
17 | test("reject process restart while reading the alias", async()=>{
|
||||
18 | const f=fixture(); f.ports.inspect=async service=>({...f.state(service),started:++f.reads[service]>1?"2026-11-16T11:01:00Z":"2026-11-16T11:00:00Z"});f.reads.api1=0;
|
||||
19 | await expect(createReplicaSnapshot(f.ports)()).rejects.toThrow("FAILOVER_REPLICA_CHANGED_DURING_READ");
|
||||
^
|
||||
error: expect(received).toThrow(expected)
|
||||
|
||||
Expected substring: "FAILOVER_REPLICA_CHANGED_DURING_READ"
|
||||
Received message: "DOCKER_CP_TMPFS_NOT_VISIBLE"
|
||||
|
||||
at <anonymous> (/Users/rey/mtuci/vp/lab7/student-tests/replica-snapshot.test.ts:19:58)
|
||||
(fail) reject process restart while reading the alias [1.22ms]
|
||||
(pass) reject malformed UUID before any stop operation [0.09ms]
|
||||
(pass) reject foreign ownership before any command [0.06ms]
|
||||
(pass) propagate native exec failure without substituting a stale alias [0.06ms]
|
||||
(pass) require explicit ports without process defaults [0.02ms]
|
||||
|
||||
4 pass
|
||||
2 fail
|
||||
6 expect() calls
|
||||
Ran 6 tests across 1 file. [25.00ms]
|
||||
Reference in New Issue
Block a user