wip: shield index relations, dev evaluation tasks, Q-063 audit notes
Verifier borrow/provenance work, new phase3 shield_index conformance cases, dev-intervals/dev-lru/dev-shards tasks with evaluate.py harness, and agent skill/hook config.
This commit is contained in:
1 parent
2d750a0525
commit
e3fc896a0a
68 files changed
+2132
-37
No files matched your search
+113
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Evaluator for dev-lru (dev set; public).
|
||||
|
||||
usage: evaluator.py WORKSPACE LANGUAGE TASK_DIR -> JSON verdict on stdout
|
||||
"""
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
import devlib # noqa: E402
|
||||
|
||||
TOKEN = re.compile(r"[a-z0-9]{1,16}")
|
||||
|
||||
|
||||
def model(text):
|
||||
lines = text.split("\n")
|
||||
if text.endswith("\n"):
|
||||
lines.pop()
|
||||
cap = int(lines[0].split(" ")[1])
|
||||
cache = OrderedDict() # least recent first
|
||||
hits = misses = evictions = 0
|
||||
out = []
|
||||
for line in lines[1:]:
|
||||
parts = line.split(" ")
|
||||
cmd, args = parts[0], parts[1:]
|
||||
if not all(TOKEN.fullmatch(a) for a in args):
|
||||
out.append("error")
|
||||
elif cmd == "put" and len(args) == 2:
|
||||
k, v = args
|
||||
if k in cache:
|
||||
out.append("ok")
|
||||
elif len(cache) == cap:
|
||||
old, _ = cache.popitem(last=False)
|
||||
evictions += 1
|
||||
out.append(f"evict {old}")
|
||||
else:
|
||||
out.append("ok")
|
||||
cache[k] = v
|
||||
cache.move_to_end(k)
|
||||
elif cmd == "get" and len(args) == 1:
|
||||
k = args[0]
|
||||
if k in cache:
|
||||
hits += 1
|
||||
cache.move_to_end(k)
|
||||
out.append(cache[k])
|
||||
else:
|
||||
misses += 1
|
||||
out.append("miss")
|
||||
elif cmd == "peek" and len(args) == 1:
|
||||
out.append(cache.get(args[0], "miss"))
|
||||
elif cmd == "del" and len(args) == 1:
|
||||
out.append("ok" if cache.pop(args[0], None) is not None else "miss")
|
||||
elif cmd == "stats" and not args:
|
||||
out.append(f"size {len(cache)} hits {hits} misses {misses} evictions {evictions}")
|
||||
elif cmd == "dump" and not args:
|
||||
out.append(" ".join(reversed(cache)) or "empty")
|
||||
else:
|
||||
out.append("error")
|
||||
return "".join(o + "\n" for o in out)
|
||||
|
||||
|
||||
def token(rng, alphabet="abcdefghijklmnopqrstuvwxyz0123456789", lo=1, hi=16):
|
||||
return "".join(rng.choice(alphabet) for _ in range(rng.randint(lo, hi)))
|
||||
|
||||
|
||||
def gen(rng, cap, n, keys, invalid=0.0):
|
||||
pool = [token(rng, lo=1, hi=8) for _ in range(keys)]
|
||||
lines = [f"capacity {cap}"]
|
||||
for _ in range(n):
|
||||
r = rng.random()
|
||||
if r < invalid:
|
||||
lines.append(rng.choice(["", "put a", "put A 1", "get", "get a b", "peek -", "del " + "x" * 17, "stats now",
|
||||
"dump 1", "put a 1", "put a 1 ", "Get a", "put a\t1", "put é 1", "evict a", "get a_b"]))
|
||||
continue
|
||||
k = rng.choice(pool)
|
||||
c = rng.random()
|
||||
if c < 0.4:
|
||||
lines.append(f"put {k} {token(rng)}")
|
||||
elif c < 0.7:
|
||||
lines.append(f"get {k}")
|
||||
elif c < 0.8:
|
||||
lines.append(f"peek {k}")
|
||||
elif c < 0.9:
|
||||
lines.append(f"del {k}")
|
||||
else:
|
||||
lines.append(rng.choice(["stats", "dump"]))
|
||||
return "\n".join(lines) + ("\n" if rng.random() < 0.8 else "")
|
||||
|
||||
|
||||
def case(text):
|
||||
return (text, model(text))
|
||||
|
||||
|
||||
PUBLIC = [case("capacity 2\nput a 1\nput b 2\nget a\nput c 3\npeek b\ndump\nget b\nstats\nput a 9\nget a\ndel zz\n")]
|
||||
|
||||
rng = random.Random(20261008)
|
||||
HIDDEN = [
|
||||
case("capacity 1\ndump\nstats\nput k v\nput k w\nget k\nput j x\ndump\nget k\nstats\n"),
|
||||
case("capacity 3\nput a 1\nput b 2\nput c 3\nget a\nput d 4\ndel c\nput e 5\ndump\nstats"),
|
||||
case("capacity 2\nput a 1\npeek a\nput b 2\nput c 3\ndump\nput b 7\nput d 8\ndump\n"),
|
||||
case("capacity 4\n\nput a 1\nput a 1 2\nput " + "z" * 16 + " " + "9" * 16 + "\nget " + "z" * 16 + "\nput " + "z" * 17 + " 1\nstats\n"),
|
||||
case(gen(rng, 3, 80, 6, invalid=0.2)),
|
||||
case(gen(rng, 10, 600, 30, invalid=0.05)),
|
||||
case(gen(rng, 50, 1200, 200, invalid=0.02)),
|
||||
case(gen(rng, 1000, 1400, 900, invalid=0.01)),
|
||||
case("capacity 1000\n" + "".join(f"put k{i} v{i}\n" for i in range(1000)) + "put kx vx\ndump\nstats\n"),
|
||||
]
|
||||
|
||||
if __name__ == "__main__":
|
||||
devlib.evaluate(devlib.Spec("lru", heap=4 << 20, fuel=400_000_000, public=PUBLIC, hidden=HIDDEN))
|
||||
@@ -0,0 +1,6 @@
|
||||
# Interface
|
||||
|
||||
- Source: `main.air`, a text AIR module.
|
||||
- Entry point: `@main(%in: cap<io.read>, %out: cap<io.write>, %heap: cap<mem.alloc>)`; any return type.
|
||||
- The program is run as `aji run --fuel 400000000 --grant in=io.read --grant out=io.write --grant heap=mem.alloc:4194304 --stdin TEXT main.air`. Standard input is TEXT; the bytes written to standard output appear in the run record's `stdout` field, and the run must end with `"status":"returned"`.
|
||||
- The heap budget is 4194304 bytes of live allocations; the run stops after 400000000 executed instructions.
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
rec=$(aji run --fuel 400000000 --grant in=io.read --grant out=io.write --grant heap=mem.alloc:4194304 --stdin 'capacity 2
|
||||
put a 1
|
||||
put b 2
|
||||
get a
|
||||
put c 3
|
||||
peek b
|
||||
dump
|
||||
get b
|
||||
stats
|
||||
put a 9
|
||||
get a
|
||||
del zz
|
||||
' main.air)
|
||||
got=$(printf '%s' "$rec" | python3 -c 'import json,sys; r=json.load(sys.stdin); print(r.get("stdout","") if r.get("status")=="returned" else "<status "+str(r.get("status"))+">", end="")') || { echo "FAIL: no run record"; echo "$rec"; exit 1; }
|
||||
expected=$(printf "%s" 'ok
|
||||
ok
|
||||
1
|
||||
evict b
|
||||
miss
|
||||
c a
|
||||
miss
|
||||
size 2 hits 1 misses 1 evictions 1
|
||||
ok
|
||||
9
|
||||
miss
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
@@ -0,0 +1,6 @@
|
||||
# Interface
|
||||
|
||||
- Source: `main.aji`, an `.aji` module.
|
||||
- Entry point: `main(input: cap<io.read>, out: cap<io.write>, heap: cap<mem.alloc>)`; any return type.
|
||||
- The program is run as `aji run --fuel 400000000 --grant input=io.read --grant out=io.write --grant heap=mem.alloc:4194304 --stdin TEXT main.aji`. Standard input is TEXT; the bytes written to standard output appear in the run record's `stdout` field, and the run must end with `"status":"returned"`.
|
||||
- The heap budget is 4194304 bytes of live allocations; the run stops after 400000000 executed instructions.
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
rec=$(aji run --fuel 400000000 --grant input=io.read --grant out=io.write --grant heap=mem.alloc:4194304 --stdin 'capacity 2
|
||||
put a 1
|
||||
put b 2
|
||||
get a
|
||||
put c 3
|
||||
peek b
|
||||
dump
|
||||
get b
|
||||
stats
|
||||
put a 9
|
||||
get a
|
||||
del zz
|
||||
' main.aji)
|
||||
got=$(printf '%s' "$rec" | python3 -c 'import json,sys; r=json.load(sys.stdin); print(r.get("stdout","") if r.get("status")=="returned" else "<status "+str(r.get("status"))+">", end="")') || { echo "FAIL: no run record"; echo "$rec"; exit 1; }
|
||||
expected=$(printf "%s" 'ok
|
||||
ok
|
||||
1
|
||||
evict b
|
||||
miss
|
||||
c a
|
||||
miss
|
||||
size 2 hits 1 misses 1 evictions 1
|
||||
ok
|
||||
9
|
||||
miss
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "lru"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,5 @@
|
||||
# Interface
|
||||
|
||||
- Cargo package `lru` in this directory; the binary is `target/debug/lru`.
|
||||
- The program reads standard input and writes standard output, as the task describes.
|
||||
- Only the standard library is available (no network, `--offline`).
|
||||
@@ -0,0 +1 @@
|
||||
fn main() {}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
cargo build -q --offline || { echo "FAIL: build"; exit 1; }
|
||||
got=$(printf '%s' 'capacity 2
|
||||
put a 1
|
||||
put b 2
|
||||
get a
|
||||
put c 3
|
||||
peek b
|
||||
dump
|
||||
get b
|
||||
stats
|
||||
put a 9
|
||||
get a
|
||||
del zz
|
||||
' | ./target/debug/lru) || { echo "FAIL: the program exited with an error"; exit 1; }
|
||||
expected=$(printf "%s" 'ok
|
||||
ok
|
||||
1
|
||||
evict b
|
||||
miss
|
||||
c a
|
||||
miss
|
||||
size 2 hits 1 misses 1 evictions 1
|
||||
ok
|
||||
9
|
||||
miss
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
@@ -0,0 +1,4 @@
|
||||
# Interface
|
||||
|
||||
- Source: `main.zig`, built with `zig build-exe main.zig` into `./main`.
|
||||
- The program reads standard input and writes standard output, as the task describes.
|
||||
@@ -0,0 +1 @@
|
||||
pub fn main() void {}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
zig build-exe main.zig 2>&1 || { echo "FAIL: build"; exit 1; }
|
||||
got=$(printf '%s' 'capacity 2
|
||||
put a 1
|
||||
put b 2
|
||||
get a
|
||||
put c 3
|
||||
peek b
|
||||
dump
|
||||
get b
|
||||
stats
|
||||
put a 9
|
||||
get a
|
||||
del zz
|
||||
' | ./main) || { echo "FAIL: the program exited with an error"; exit 1; }
|
||||
expected=$(printf "%s" 'ok
|
||||
ok
|
||||
1
|
||||
evict b
|
||||
miss
|
||||
c a
|
||||
miss
|
||||
size 2 hits 1 misses 1 evictions 1
|
||||
ok
|
||||
9
|
||||
miss
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
@@ -0,0 +1,69 @@
|
||||
# Task: least-recently-used cache
|
||||
|
||||
Development task (dev set). Its results are not evidence about any language.
|
||||
|
||||
Write a program that simulates a key–value cache of bounded size which evicts the least recently used key. The program reads commands from standard input, one per line, and writes its answers to standard output.
|
||||
|
||||
## Input
|
||||
|
||||
The input is a sequence of lines separated by `\n`. If the input ends with `\n`, that final `\n` does not start another line. The input is at most 32 KiB and has at most 1500 lines.
|
||||
|
||||
The first line is always `capacity C`, where C is a decimal number with 1 ≤ C ≤ 1000 and no leading zeros. It produces no output. Every later line is a command.
|
||||
|
||||
A **token** is 1 to 16 characters, each an ASCII lowercase letter `a`–`z` or digit `0`–`9`. Keys and values are tokens.
|
||||
|
||||
A line is a valid command when it is exactly one of the forms below: the command word, then its arguments, each separated by exactly one space. There are no other spaces or characters.
|
||||
|
||||
| Command | Effect | Output |
|
||||
|---|---|---|
|
||||
| `put K V` | If K is in the cache, its value becomes V. Otherwise, if the cache holds C keys, the least recently used key L is removed first, then K is added with value V. In both cases K becomes the most recently used key. | `evict L` if a key was removed, otherwise `ok` |
|
||||
| `get K` | If K is in the cache, K becomes the most recently used key. | the value of K, or `miss` |
|
||||
| `peek K` | Nothing changes. | the value of K, or `miss` |
|
||||
| `del K` | Removes K if it is in the cache. | `ok` if it was removed, otherwise `miss` |
|
||||
| `stats` | Nothing changes. | `size S hits H misses M evictions E` |
|
||||
| `dump` | Nothing changes. | the keys from the most to the least recently used, separated by single spaces; `empty` if the cache is empty |
|
||||
|
||||
**Recency** changes only through `put` and a `get` that finds its key. S is the number of keys in the cache. H and M count the `get` commands that found and did not find their key; `peek` is not counted. E counts the keys removed by `put`; `del` is not counted.
|
||||
|
||||
Any other line, including an empty line, an unknown command, a wrong number of arguments, or an argument that is not a token, is **invalid**. For an invalid line the program writes `error` and changes nothing.
|
||||
|
||||
## Output
|
||||
|
||||
One output line for each command and for each invalid line, in input order. Every output line ends with `\n`. Nothing else is written to standard output.
|
||||
|
||||
## Example
|
||||
|
||||
Input:
|
||||
|
||||
```text
|
||||
capacity 2
|
||||
put a 1
|
||||
put b 2
|
||||
get a
|
||||
put c 3
|
||||
peek b
|
||||
dump
|
||||
get b
|
||||
stats
|
||||
put a 9
|
||||
get a
|
||||
del zz
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```text
|
||||
ok
|
||||
ok
|
||||
1
|
||||
evict b
|
||||
miss
|
||||
c a
|
||||
miss
|
||||
size 2 hits 1 misses 1 evictions 1
|
||||
ok
|
||||
9
|
||||
miss
|
||||
```
|
||||
|
||||
The repository contains a README with the program's interface for this language and a public test script, `sh test.sh`, which must pass. Hidden tests check the requirements above, including invalid input.
|
||||
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "lru"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,61 @@
|
||||
use std::collections::HashMap;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
fn token(t: &str) -> bool {
|
||||
(1..=16).contains(&t.len()) && t.bytes().all(|b| b.is_ascii_lowercase() || b.is_ascii_digit())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_to_string(&mut input).unwrap();
|
||||
let mut lines: Vec<&str> = input.split('\n').collect();
|
||||
if input.ends_with('\n') {
|
||||
lines.pop();
|
||||
}
|
||||
let cap: usize = lines[0]["capacity ".len()..].parse().unwrap();
|
||||
// key -> (value, last use); recency is the use counter.
|
||||
let mut map: HashMap<String, (String, u64)> = HashMap::new();
|
||||
let (mut clock, mut hits, mut misses, mut evictions) = (0u64, 0u64, 0u64, 0u64);
|
||||
let mut out = String::new();
|
||||
for line in &lines[1..] {
|
||||
let parts: Vec<&str> = line.split(' ').collect();
|
||||
let args = &parts[1..];
|
||||
if !args.iter().all(|a| token(a)) {
|
||||
out.push_str("error\n");
|
||||
continue;
|
||||
}
|
||||
clock += 1;
|
||||
match (parts[0], args) {
|
||||
("put", [k, v]) => {
|
||||
if map.contains_key(*k) {
|
||||
out.push_str("ok\n");
|
||||
} else if map.len() == cap {
|
||||
let old = map.iter().min_by_key(|(_, (_, t))| *t).map(|(k, _)| k.clone()).unwrap();
|
||||
map.remove(&old);
|
||||
evictions += 1;
|
||||
out.push_str(&format!("evict {old}\n"));
|
||||
} else {
|
||||
out.push_str("ok\n");
|
||||
}
|
||||
map.insert(k.to_string(), (v.to_string(), clock));
|
||||
}
|
||||
("get", [k]) => match map.get_mut(*k) {
|
||||
Some((v, t)) => { *t = clock; hits += 1; out.push_str(&format!("{v}\n")); }
|
||||
None => { misses += 1; out.push_str("miss\n"); }
|
||||
},
|
||||
("peek", [k]) => out.push_str(&format!("{}\n", map.get(*k).map_or("miss", |(v, _)| v.as_str()))),
|
||||
("del", [k]) => out.push_str(if map.remove(*k).is_some() { "ok\n" } else { "miss\n" }),
|
||||
("stats", []) => out.push_str(&format!("size {} hits {hits} misses {misses} evictions {evictions}\n", map.len())),
|
||||
("dump", []) => {
|
||||
let mut keys: Vec<(&String, u64)> = map.iter().map(|(k, (_, t))| (k, *t)).collect();
|
||||
keys.sort_by(|a, b| b.1.cmp(&a.1));
|
||||
let s: Vec<&str> = keys.iter().map(|(k, _)| k.as_str()).collect();
|
||||
out.push_str(if s.is_empty() { "empty" } else { "" });
|
||||
out.push_str(&s.join(" "));
|
||||
out.push('\n');
|
||||
}
|
||||
_ => out.push_str("error\n"),
|
||||
}
|
||||
}
|
||||
std::io::stdout().write_all(out.as_bytes()).unwrap();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
cargo build -q --offline || { echo "FAIL: build"; exit 1; }
|
||||
got=$(printf '%s' 'capacity 2
|
||||
put a 1
|
||||
put b 2
|
||||
get a
|
||||
put c 3
|
||||
peek b
|
||||
dump
|
||||
get b
|
||||
stats
|
||||
put a 9
|
||||
get a
|
||||
del zz
|
||||
' | ./target/debug/lru) || { echo "FAIL: the program exited with an error"; exit 1; }
|
||||
expected=$(printf "%s" 'ok
|
||||
ok
|
||||
1
|
||||
evict b
|
||||
miss
|
||||
c a
|
||||
miss
|
||||
size 2 hits 1 misses 1 evictions 1
|
||||
ok
|
||||
9
|
||||
miss
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"id": "dev-lru",
|
||||
"version": "1",
|
||||
"set": "dev",
|
||||
"family": "failure-calibration",
|
||||
"prompt": "prompt.md",
|
||||
"languages": {
|
||||
"aji_air": {"workspace": "lang/aji_air", "test": "sh test.sh"},
|
||||
"aji_source": {"workspace": "lang/aji_source", "test": "sh test.sh"},
|
||||
"rust": {"workspace": "lang/rust", "test": "sh test.sh"},
|
||||
"zig": {"workspace": "lang/zig", "test": "sh test.sh"}
|
||||
},
|
||||
"limits": {"tool_calls": 80, "total_tokens": 1500000, "wall_seconds": 1800, "command_timeout": 120},
|
||||
"concurrency": false
|
||||
}
|
||||
Reference in new issue
Block a user