Artifact 7058925a7f0b1e8ba99fc0bcca5f6b9a428a3a88a6773d92b793c261152f5a7a:
- File
Makefile
— part of check-in
[eae917e9e9]
at
2026-11-21 12:03:36
on branch shared-store
— Shared journal store: several pic processes on one workspace, one conversation each
Each conversation has a lease (an exclusive flock beside the journal) that its process holds while it advances it and that the kernel drops when the process and its forked children are gone. Taking a lease claims the conversation's request and settles what a dead owner left; open recovers only conversations whose lease is free. The journal lock is held shared and taken exclusive only to create or migrate the schema. SQLite runs in normal locking mode with the fair busy handler; dev builds stop on a write begun under an open read.
pic run takes only requests nobody is running. A second pic asking into a conversation in use is refused with its owner's pid. An edit that misses in a file another conversation changed says so and shows the file; a write to such a file is refused once.
New test/pic/shared.sh: two-process crash matrix, kill -9 beside a live pic, claim and admission races, stale-file results. No schema change. (user: dmestas, size: 25502) [annotate] [blame] [check-ins using] [more...]
# pic harness plus S0/S1 qualification gates.
CC ?= cc
PYTHON ?= python3
export CC
.PHONY: all check metadata test test-reporting replay dst sanitize coverage-mcdc \
fuzz-smoke bench filc-remote qualify help assertion-guard local-evidence test-context test-context-sanitize test-remote \
pic pic-dev test-pic test-pic-run test-docs test-sqlite3 test-sse test-tui test-highlight test-decode test-http test-files test-models test-userdb test-cred test-xfer test-prompts test-skills test-provider fuzz-decode fuzz-http fuzz-chat fuzz-responses bench-pic bench-pic-record install-pic
all: check
check: test-pic metadata test-reporting replay coverage-mcdc assertion-guard test-remote
@printf '%s\n' 'PASS: pic crash/recovery suite and local qualification gates.'
metadata:
$(PYTHON) -I -B test/test_contracts.py
$(PYTHON) -I -B tools/check_contracts.py
test-reporting:
$(PYTHON) -I -B test/test_toolchain.py
test:
sh tools/test-native.sh normal
# The normal suite includes the fixed 100-seed deterministic replay campaign.
dst: test
replay: test
sh tools/test-native.sh replay
sanitize:
sh tools/test-native.sh sanitize
coverage-mcdc:
sh tools/mcdc.sh
assertion-guard:
sh tools/test-assertions.sh
fuzz-smoke:
sh tools/test-native.sh fuzz
bench:
sh tools/benchmark.sh
test-context:
sh test/context/test-driver.sh normal
test-context-sanitize:
sh test/context/test-driver.sh sanitize
test-remote:
sh test/test_remote_lifecycle.sh
$(PYTHON) -I -B test/remote/test_collect.py
# Run actual local gates before snapshotting metadata; never reuse a stale PASS.
local-evidence:
mkdir -p build/qualification
rm -f build/qualification/local-evidence.json
$(MAKE) check sanitize fuzz-smoke bench > build/qualification/local-checks.log 2>&1
$(PYTHON) -I -B tools/evidence.py --log build/qualification/local-checks.log
$(PYTHON) -I -B tools/check_contracts.py --evidence build/qualification/local-evidence.json
# Remote evidence gate; actual host operations remain explicit.
filc-remote:
@test -n "$(REMOTE_RUN)" || { printf '%s\n' 'GATED: supply REMOTE_RUN=/absolute/completed/filc-run; see docs/dev/filc.md'; exit 2; }
sh tools/remote/run.sh reconcile "$(REMOTE_RUN)" > "$(REMOTE_RUN)/operator-reconcile.log"
$(PYTHON) -I -B tools/remote/report.py "$(REMOTE_RUN)"
$(PYTHON) -I -B tools/check_contracts.py --evidence "$(REMOTE_RUN)/qualification.json"
qualify: check sanitize fuzz-smoke bench
@printf '%s\n' 'GATED: local fixture evidence is not release qualification.' \
'Production runtime/release contracts remain unqualified; remote fixture evidence is a separate explicit gate.'
@exit 2
help:
@printf '%s\n' 'S0 only: check, metadata, test, dst, replay, sanitize, coverage-mcdc,' \
'fuzz-smoke, bench, test-context, test-context-sanitize, test-remote.' \
'filc-remote verifies an explicit REMOTE_RUN; full production qualify remains GATED.'
# ---- pic: the harness ------------------------------------------------------
# Release has no test code and no fault hooks; dev adds ASan/UBSan and crash points.
PIC_SRC := src/store.c src/prune.c src/image.c src/platform.c src/input.c src/userdb.c src/sqlar.c src/catalog.c src/catalog_fetch.c src/loop.c src/compact.c src/events.c src/export_pi.c src/export_html.c src/import_pi.c src/import_claude.c src/tree.c src/commands.c src/rpc.c src/tui/app.c src/tui/width.c src/tui/term.c src/tui/render.c src/tui/editor.c src/tui/fuzzy.c src/tui/atfile.c src/tui/clipboard.c src/tui/view.c src/tui/transcript.c src/tui/viewport.c src/tui/markdown.c src/tui/highlight.c src/tui/theme.c src/tui/themes.c src/tui/keymap.c src/tui/mjson.c src/skills.c src/hooks.c src/procs.c src/ignore.c src/provider_fake.c src/provider_anthropic.c src/tools.c src/toolpar.c src/search.c src/bash.c src/context.c src/prompts.c \
src/sse.c src/anthropic.c src/openai_chat.c src/openai_responses.c src/gemini.c src/provider_http.c src/provider_chat.c \
src/provider_responses.c src/provider_gemini.c src/http.c src/net.c src/xfer.c src/cred.c \
src/models.c src/transform.c src/main.c
PIC_HDR := src/pic.h src/tui/highlight.h src/tui/theme.h src/tui/themes.h src/tui/keymap.h src/tui/mjson.h src/tui/theme_dark.inc src/tui/theme_light.inc src/gemini.h src/image.h src/platform.h src/input.h src/ca_bundle.inc src/userdb.h src/sqlar.h src/compact.h src/events.h src/catalog.h src/models.h src/tui/fuzzy.h src/tui/atfile.h src/tui/clipboard.h src/tui/view.h src/tui/transcript.h src/tui/viewport.h src/tui/markdown.h src/tui/tui.h src/tui/width.h src/tui/term.h src/tui/render.h src/tui/editor.h src/sse.h src/anthropic.h src/openai_chat.h src/openai_responses.h src/provider_http.h src/http.h \
src/net.h src/xfer.h src/cred.h src/commands.h src/rpc.h src/procs.h src/toolpar.h \
src/models.h src/prompts.h src/skills.h src/hooks.h src/ignore.h src/changelog.inc
# /changelog's text is compiled in; CHANGELOG.md is the source. The .inc is
# built, never committed, so landings do not conflict on it. Objects wait for
# it (order-only) because a clean tree has no -MMD dependencies yet.
src/changelog.inc: CHANGELOG.md tools/changelog-inc.sh
sh tools/changelog-inc.sh CHANGELOG.md > [email protected] && mv -f [email protected] $@
PIC_VENDOR := vendor/libfossil
# Dependencies are vendored and compiled in (vendor/*/SHA256SUMS); the binary
# links only libc, libm and pthread. No iconv, no -ldl, no system zlib.
PIC_SQLITE := -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_THREADSAFE=1 \
-DSQLITE_OMIT_LOAD_EXTENSION
PIC_VFLAGS := $(PIC_SQLITE) -DHAVE_LIBFOSSIL_CONFIG_H -DWITHOUT_ICONV -DZ_HAVE_UNISTD_H -w \
-I$(PIC_VENDOR) -Ivendor/zlib
PIC_WARN := -std=c11 -Wall -Wextra -Wpedantic -Werror -Wshadow -Wconversion \
-Wstrict-prototypes -Wmissing-prototypes -Wvla -Wcast-qual -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE
# gcc's -Wformat-truncation (no clang equivalent) fires on snprintf into the
# fixed error and display buffers, where a clipped message is the intended
# outcome; its absence from the fatal set keeps gcc builds working. Both
# compilers accept the flag silently. _GNU_SOURCE is what glibc needs to
# declare strptime (Darwin ignores it; it has _DARWIN_C_SOURCE already).
PIC_WARN += -Wno-format-truncation -D_GNU_SOURCE
PIC_INC := -Isrc -isystem $(PIC_VENDOR) -isystem vendor/zlib -DHAVE_LIBFOSSIL_CONFIG_H
PIC_SAN := -O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=all
PIC_LIBS := -lm -lpthread
PIC_ZLIB := adler32 compress crc32 deflate inffast inflate inftrees trees uncompr zutil
build/pic/release/vendor/%.o: $(PIC_VENDOR)/%.c
@mkdir -p $(@D)
$(CC) -O2 $(PIC_VFLAGS) -c -o $@ $<
build/pic/dev/vendor/%.o: $(PIC_VENDOR)/%.c
@mkdir -p $(@D)
$(CC) $(PIC_SAN) $(PIC_VFLAGS) -c -o $@ $<
build/pic/release/vendor/zlib/%.o: vendor/zlib/%.c
@mkdir -p $(@D)
$(CC) -O2 $(PIC_VFLAGS) -c -o $@ $<
build/pic/dev/vendor/zlib/%.o: vendor/zlib/%.c
@mkdir -p $(@D)
$(CC) $(PIC_SAN) $(PIC_VFLAGS) -c -o $@ $<
PIC_REL_V := build/pic/release/vendor/sqlite3.o build/pic/release/vendor/libfossil.o \
$(PIC_ZLIB:%=build/pic/release/vendor/zlib/%.o)
PIC_DEV_V := build/pic/dev/vendor/sqlite3.o build/pic/dev/vendor/libfossil.o \
$(PIC_ZLIB:%=build/pic/dev/vendor/zlib/%.o)
# BearSSL makes no system call of its own: net.c seeds it and gives it the date.
PIC_BRFLAGS := -w -Ivendor/bearssl/inc -Ivendor/bearssl/src -DBR_RDRAND=0 -DBR_USE_URANDOM=0 \
-DBR_USE_WIN32_RAND=0 -DBR_USE_UNIX_TIME=0 -DBR_USE_WIN32_TIME=0
PIC_BR_SRC := $(sort $(wildcard vendor/bearssl/src/*.c vendor/bearssl/src/*/*.c))
PIC_BR_REL := $(PIC_BR_SRC:vendor/bearssl/src/%.c=build/pic/release/vendor/bearssl/%.o)
PIC_BR_DEV := $(PIC_BR_SRC:vendor/bearssl/src/%.c=build/pic/dev/vendor/bearssl/%.o)
build/pic/release/vendor/bearssl/%.o: vendor/bearssl/src/%.c
@mkdir -p $(@D)
$(CC) -O2 $(PIC_BRFLAGS) -c -o $@ $<
build/pic/dev/vendor/bearssl/%.o: vendor/bearssl/src/%.c
@mkdir -p $(@D)
$(CC) $(PIC_SAN) $(PIC_BRFLAGS) -c -o $@ $<
build/pic/release/vendor/libbearssl.a: $(PIC_BR_REL)
ar rcs $@ $^
build/pic/dev/vendor/libbearssl.a: $(PIC_BR_DEV)
ar rcs $@ $^
PIC_NET := src/net.c src/input.c src/platform.c src/http.c
PIC_NET_INC := -isystem vendor/bearssl/inc
build/pic/dev/test_http: test/pic/test_http.c $(PIC_NET) src/http.h src/net.h build/pic/dev/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) -Isrc $(PIC_NET_INC) -o $@ test/pic/test_http.c $(PIC_NET) \
build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
# Installs the release binary for everyday use, only after the full suite
# passes. Copy then rename, so a pic already running keeps its own binary.
PIC_INSTALL_DIR ?= $(shell printf %s "$$HOME")/.local/bin
install-pic: test-pic
@mkdir -p $(PIC_INSTALL_DIR)
cp build/pic/release/pic $(PIC_INSTALL_DIR)/.pic.new
chmod 755 $(PIC_INSTALL_DIR)/.pic.new
mv -f $(PIC_INSTALL_DIR)/.pic.new $(PIC_INSTALL_DIR)/pic
@printf 'installed %s/pic\n' "$(PIC_INSTALL_DIR)"
# pic's own sources compile once each into per-flavor objects (header
# dependencies via -MMD), so a parallel make spreads them over every core.
# Dev adds the sanitizers and crash points; release has neither.
PIC_OBJ := $(PIC_SRC:src/%.c=%.o)
PIC_DEV_OBJ := $(PIC_OBJ:%=build/pic/dev/obj/%)
PIC_REL_OBJ := $(PIC_OBJ:%=build/pic/release/obj/%)
build/pic/dev/obj/%.o: src/%.c
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) -DPIC_FAULTS $(PIC_INC) $(PIC_NET_INC) -MMD -MP -c -o $@ $<
build/pic/release/obj/%.o: src/%.c
@mkdir -p $(@D)
$(CC) $(PIC_WARN) -O2 $(PIC_INC) $(PIC_NET_INC) -MMD -MP -c -o $@ $<
-include $(PIC_DEV_OBJ:.o=.d) $(PIC_REL_OBJ:.o=.d)
$(PIC_DEV_OBJ) $(PIC_REL_OBJ): | src/changelog.inc
# Benchmarks run on release-flag objects, so they measure what users run.
build/pic/pic_bench: bench/pic_bench.c $(filter-out build/pic/release/obj/main.o,$(PIC_REL_OBJ)) $(PIC_HDR) $(PIC_REL_V) build/pic/release/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_WARN) -O2 $(PIC_INC) $(PIC_NET_INC) -o $@ bench/pic_bench.c $(filter-out build/pic/release/obj/main.o,$(PIC_REL_OBJ)) \
$(PIC_REL_V) build/pic/release/vendor/libbearssl.a $(PIC_LIBS)
bench-pic: build/pic/pic_bench build/pic/release/pic
sh bench/pic-bench.sh build/pic/pic_bench build/pic/release/pic
bench-pic-record: build/pic/pic_bench build/pic/release/pic
sh bench/pic-bench.sh build/pic/pic_bench build/pic/release/pic --record
build/pic/fake_server: test/pic/fake_server.c
@mkdir -p $(@D)
$(CC) -std=c11 -Wall -Wextra -Werror -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE -O1 -o $@ test/pic/fake_server.c
test-http: build/pic/dev/test_http
build/pic/dev/test_http
build/pic/dev/test_files: test/pic/test_files.c src/tools.c src/image.c src/image.h src/pic.h $(PIC_NET) build/pic/dev/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) $(PIC_INC) $(PIC_NET_INC) -o $@ test/pic/test_files.c src/tools.c src/image.c $(PIC_NET) \
build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
test-files: build/pic/dev/test_files
build/pic/dev/test_files
build/pic/dev/test_prompts: test/pic/test_prompts.c src/prompts.c src/prompts.h src/input.c src/platform.c src/platform.h
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) -Isrc -o $@ test/pic/test_prompts.c src/prompts.c src/input.c src/platform.c
test-prompts: build/pic/dev/test_prompts
build/pic/dev/test_prompts
build/pic/dev/test_skills: test/pic/test_skills.c src/skills.c src/skills.h src/ignore.c src/ignore.h src/prompts.c src/prompts.h src/input.c src/platform.c src/platform.h build/pic/dev/vendor/sqlite3.o
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) -Isrc -isystem $(PIC_VENDOR) -o $@ test/pic/test_skills.c src/skills.c src/ignore.c src/prompts.c src/input.c src/platform.c build/pic/dev/vendor/sqlite3.o $(PIC_LIBS)
test-skills: build/pic/dev/test_skills
# Hooks under an executor without spawn (the no-OS build's shape).
build/pic/dev/test_hooks: test/pic/test_hooks.c $(filter-out build/pic/dev/obj/main.o,$(PIC_DEV_OBJ)) $(PIC_HDR) $(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) $(PIC_INC) $(PIC_NET_INC) -o $@ test/pic/test_hooks.c $(filter-out build/pic/dev/obj/main.o,$(PIC_DEV_OBJ)) \
$(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
test-hooks: build/pic/dev/test_hooks
ASAN_OPTIONS=detect_leaks=0 build/pic/dev/test_hooks
build/pic/dev/test_skills
build/pic/dev/test_models: test/pic/test_models.c src/models.c src/models.h src/userdb.c src/sqlar.c src/catalog.c src/catalog.h src/model_catalog.inc src/cred.c src/cred.h $(PIC_DEV_V) \
build/pic/dev/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) $(PIC_INC) $(PIC_NET_INC) -o $@ test/pic/test_models.c src/models.c src/input.c src/platform.c src/catalog.c src/userdb.c src/sqlar.c \
src/cred.c $(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
test-models: build/pic/dev/test_models
build/pic/dev/test_models
build/pic/dev/test_userdb: test/pic/test_userdb.c src/userdb.c src/userdb.h src/procs.c src/procs.h src/sqlar.c src/platform.c src/input.c $(PIC_DEV_V)
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) $(PIC_INC) -o $@ test/pic/test_userdb.c src/userdb.c src/procs.c src/sqlar.c src/input.c src/platform.c $(PIC_DEV_V) $(PIC_LIBS)
build/pic/dev/test_cred: test/pic/test_cred.c src/cred.c src/cred.h src/userdb.c src/userdb.h src/sqlar.c src/platform.c src/platform.h src/input.c \
$(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) $(PIC_INC) $(PIC_NET_INC) -o $@ test/pic/test_cred.c src/cred.c src/userdb.c src/sqlar.c \
src/input.c src/platform.c $(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
# A HOME of its own: the store test needs a pic.sqlite with no credentials.
test-cred: build/pic/dev/test_cred
rm -rf build/pic/cred-home && mkdir -p build/pic/cred-home
HOME="$(CURDIR)/build/pic/cred-home" build/pic/dev/test_cred
build/pic/dev/test_xfer: test/pic/test_xfer.c src/xfer.c src/xfer.h src/net.c src/net.h src/input.c src/platform.c $(PIC_DEV_V) \
build/pic/dev/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) $(PIC_INC) $(PIC_NET_INC) -o $@ test/pic/test_xfer.c src/xfer.c src/net.c src/input.c \
src/platform.c $(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
# A fresh HOME: the test checks that no password reached ~/.fossil.
test-xfer: build/pic/dev/test_xfer
rm -rf build/pic/xfer-home && mkdir -p build/pic/xfer-home
HOME="$(CURDIR)/build/pic/xfer-home" build/pic/dev/test_xfer
# A HOME of its own: the busy and contention cases need a fresh pic.sqlite.
test-userdb: build/pic/dev/test_userdb
rm -rf build/pic/userdb-home && mkdir -p build/pic/userdb-home
HOME="$(CURDIR)/build/pic/userdb-home" build/pic/dev/test_userdb
# The spike: one live streaming request over pic's own HTTPS stack.
build/pic/dev/live_probe: test/pic/live_probe.c $(PIC_NET) src/net.h src/http.h src/anthropic.c src/sse.c \
$(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a
$(CC) $(PIC_WARN) $(PIC_SAN) $(PIC_INC) $(PIC_NET_INC) -o $@ test/pic/live_probe.c $(PIC_NET) \
src/anthropic.c src/sse.c $(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
build/pic/release/pic: $(PIC_REL_OBJ) $(PIC_REL_V) build/pic/release/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) -O2 -o $@ $(PIC_REL_OBJ) $(PIC_REL_V) build/pic/release/vendor/libbearssl.a $(PIC_LIBS)
build/pic/dev/pic: $(PIC_DEV_OBJ) $(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_SAN) -o $@ $(PIC_DEV_OBJ) $(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
# The sqlite3 command the tests use, built from the vendored shell.c and
# sqlite3.c (the release object, same flags) with zlib for sqlar_uncompress.
# Tests put build/pic first on PATH, so no host sqlite3 is ever needed.
build/pic/vendor-shell.o: $(PIC_VENDOR)/shell.c
@mkdir -p $(@D)
$(CC) -O2 $(PIC_VFLAGS) -DSQLITE_HAVE_ZLIB -c -o $@ $<
build/pic/sqlite3: build/pic/vendor-shell.o build/pic/release/vendor/sqlite3.o $(PIC_ZLIB:%=build/pic/release/vendor/zlib/%.o)
$(CC) -O2 -o $@ $^ $(PIC_LIBS)
test-sqlite3: build/pic/sqlite3
sh test/pic/sqlite3.sh build/pic/sqlite3 $(PIC_VENDOR)/sqlite3.h
pic: build/pic/release/pic
pic-dev: build/pic/dev/pic
# Tests and benchmarks never touch the real ~/.pic: a private HOME, no network catalog.
test-pic test-pic-run test-sqlite3 test-sse test-tui test-highlight test-decode test-http test-files test-models test-userdb test-cred test-xfer test-prompts test-skills test-hooks test-provider bench-pic bench-pic-record: export HOME := $(CURDIR)/build/pic
test-pic test-pic-run test-sqlite3 test-sse test-tui test-highlight test-decode test-http test-files test-models test-userdb test-cred test-xfer test-prompts test-skills test-hooks test-provider bench-pic bench-pic-record: export PIC_MODEL_CATALOG := offline
test-pic test-pic-run test-sqlite3 test-sse test-tui test-highlight test-decode test-http test-files test-models test-userdb test-cred test-xfer test-prompts test-skills test-hooks test-provider test-sqlite3 bench-pic bench-pic-record: export SQLITE3 := $(CURDIR)/build/pic/sqlite3
test-pic test-pic-run test-sqlite3 test-sse test-tui test-highlight test-decode test-http test-files test-models test-userdb test-cred test-xfer test-prompts test-skills test-hooks test-provider bench-pic bench-pic-record: export PATH := $(CURDIR)/build/pic:$(PATH)
# test-pic builds everything and runs every suite in parallel, one job per
# core by default (JOBS=1 restores the serial order). Each script owns a
# private temp dir, HOME and server port, so they do not share state; each
# runs under test/run-logged.sh, which keeps its output in build/pic/logs and
# prints the log only when the script fails.
JOBS ?= $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
PIC_LOGDIR := build/pic/logs
PIC_RUN := sh test/run-logged.sh $(PIC_LOGDIR)
PIC_DEV_ENV := ASAN_OPTIONS=detect_leaks=0 PIC="$(CURDIR)/build/pic/dev/pic" SERVER="$(CURDIR)/build/pic/fake_server" DRIVE="$(CURDIR)/build/pic/pty_drive"
PIC_REL_ENV := PIC="$(CURDIR)/build/pic/release/pic" SERVER="$(CURDIR)/build/pic/fake_server" DRIVE="$(CURDIR)/build/pic/pty_drive"
# name:script, with a "!" suffix on the name when the release run takes --no-faults.
PIC_SCRIPTS := crash!:test/pic/crash.sh tools!:test/pic/tools.sh migrate:test/pic/migrate.sh \
sessions!:test/pic/sessions.sh compact!:test/pic/compact.sh images!:test/pic/images.sh \
branch!:test/pic/branch.sh compact_settings:test/pic/compact_settings.sh \
events:test/pic/events.sh interrupt:test/pic/interrupt.sh steer:test/pic/steer.sh \
bash:test/pic/bash.sh chat:test/pic/chat.sh export_pi:test/pic/export_pi.sh import_claude:test/pic/import_claude.sh \
catalog:test/pic/catalog.sh cost:test/pic/cost.sh slash:test/pic/slash.sh projects:test/pic/projects.sh \
prompts:test/pic/prompts.sh skills:test/pic/skills.sh hooks!:test/pic/hooks.sh tui:test/tui/tui.sh paste:test/tui/paste.sh themes:test/tui/themes.sh search:test/tui/search.sh \
provider!:test/pic/provider.sh bench!:test/pic/bench.sh ps:test/pic/ps.sh print:test/pic/print.sh toolset:test/pic/toolset.sh \
creds!:test/pic/creds.sh rpc:test/pic/rpc.sh parallel!:test/pic/parallel.sh shared!:test/pic/shared.sh
PIC_SCRIPT_NAMES := $(foreach e,$(PIC_SCRIPTS),$(subst !,,$(firstword $(subst :, ,$(e)))))
PIC_RUN_TARGETS := $(foreach n,$(PIC_SCRIPT_NAMES),run-$(n)-dev run-$(n)-rel)
define pic_script_rules
run-$(1)-dev: build/pic/dev/pic build/pic/fake_server build/pic/pty_drive build/pic/sqlite3
@$$(PIC_RUN) $(1)-dev $$(PIC_DEV_ENV) sh $(2)
run-$(1)-rel: build/pic/release/pic build/pic/fake_server build/pic/pty_drive build/pic/sqlite3
@$$(PIC_RUN) $(1)-rel $$(PIC_REL_ENV) sh $(2) $(3)
endef
$(foreach e,$(PIC_SCRIPTS),$(eval $(call pic_script_rules,$(subst !,,$(firstword $(subst :, ,$(e)))),$(lastword $(subst :, ,$(e))),$(if $(findstring !,$(firstword $(subst :, ,$(e)))),--no-faults))))
.PHONY: $(PIC_RUN_TARGETS) test-pic-run
test-pic:
@rm -rf $(PIC_LOGDIR) && mkdir -p $(PIC_LOGDIR)
$(MAKE) -k -j$(JOBS) test-pic-run
test-provider: run-provider-dev run-provider-rel
# The reference in docs/reference/ against src/, the README budget, links and
# the generated key table (docs/dev/testing.md).
test-docs:
sh test/pic/docs.sh
test-pic-run: test-docs test-sse test-tui test-highlight test-decode test-http test-files test-models test-userdb test-cred test-xfer test-prompts test-skills test-hooks test-sqlite3 $(PIC_RUN_TARGETS)
build/pic/dev/test_sse: test/pic/test_sse.c src/sse.c src/sse.h
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) -Isrc -o $@ test/pic/test_sse.c src/sse.c
test-sse: build/pic/dev/test_sse
build/pic/dev/test_sse
PIC_TUI_UNITS := src/tui/width.c src/tui/term.c src/tui/render.c src/tui/editor.c src/tui/fuzzy.c src/tui/atfile.c src/tui/view.c src/tui/transcript.c src/tui/viewport.c src/tui/markdown.c src/tui/highlight.c src/tui/theme.c src/tui/themes.c src/tui/keymap.c src/tui/mjson.c src/ignore.c src/input.c src/platform.c
build/pic/dev/test_tui: test/tui/test_tui.c $(PIC_TUI_UNITS) build/pic/dev/vendor/sqlite3.o src/ignore.h src/tui/highlight.h src/tui/width.h src/tui/term.h src/tui/render.h src/tui/editor.h src/tui/view.h src/tui/transcript.h src/tui/viewport.h src/tui/markdown.h src/tui/theme.h src/tui/themes.h src/tui/keymap.h src/tui/mjson.h src/tui/theme_dark.inc src/tui/theme_light.inc
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) -Isrc -isystem $(PIC_VENDOR) -o $@ test/tui/test_tui.c $(PIC_TUI_UNITS) build/pic/dev/vendor/sqlite3.o $(PIC_LIBS)
test-tui: build/pic/dev/test_tui
build/pic/dev/test_tui
build/pic/dev/test_highlight: test/tui/test_highlight.c src/tui/highlight.c src/tui/highlight.h src/tui/width.c src/tui/width.h
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) -Isrc -o $@ test/tui/test_highlight.c src/tui/highlight.c src/tui/width.c
test-highlight: build/pic/dev/test_highlight
build/pic/dev/test_highlight
build/pic/pty_drive: test/tui/pty_drive.c
@mkdir -p $(@D)
$(CC) -std=c11 -Wall -Wextra -Werror -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE=600 -O1 -o $@ test/tui/pty_drive.c
build/pic/dev/decode_stream: test/pic/decode_stream.c src/anthropic.c src/anthropic.h src/openai_chat.c src/openai_chat.h src/openai_responses.c src/openai_responses.h src/gemini.c src/gemini.h \
src/sse.c src/sse.h $(PIC_DEV_V)
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) $(PIC_INC) -o $@ test/pic/decode_stream.c src/anthropic.c src/openai_chat.c src/openai_responses.c src/gemini.c src/sse.c \
$(PIC_DEV_V) $(PIC_LIBS)
test-decode: build/pic/dev/decode_stream
sh test/pic/decode.sh build/pic/dev/decode_stream
# libFuzzer needs an LLVM clang (Apple's lacks it). SQLite is rebuilt with the
# same compiler so one sanitizer runtime is linked. FUZZ_SECONDS bounds a run;
# new findings land in build/pic/fuzz/ and become fixtures when fixed.
FUZZ_CC ?= $(firstword $(wildcard /opt/homebrew/opt/llvm/bin/clang /usr/local/opt/llvm/bin/clang) clang)
FUZZ_SECONDS ?= 60
FUZZ_FLAGS := -O1 -g -fsanitize=fuzzer,address,undefined -fno-sanitize-recover=all
build/pic/fuzz/sqlite3.o: $(PIC_VENDOR)/sqlite3.c
@mkdir -p $(@D)
$(FUZZ_CC) -O1 -g -fsanitize=fuzzer-no-link,address,undefined $(PIC_SQLITE) -w -c -o $@ $<
build/pic/fuzz/fuzz_decode: test/fuzz/fuzz_decode.c src/anthropic.c src/anthropic.h src/sse.c src/sse.h build/pic/fuzz/sqlite3.o
$(FUZZ_CC) $(PIC_WARN) $(FUZZ_FLAGS) -Isrc -isystem $(PIC_VENDOR) -o $@ test/fuzz/fuzz_decode.c src/anthropic.c src/sse.c build/pic/fuzz/sqlite3.o -lm -lpthread
fuzz-decode: build/pic/fuzz/fuzz_decode
@mkdir -p build/pic/fuzz/corpus build/pic/fuzz/findings
build/pic/fuzz/fuzz_decode -max_total_time=$(FUZZ_SECONDS) -max_len=8192 -timeout=10 -dict=test/fuzz/sse.dict \
-artifact_prefix=build/pic/fuzz/findings/ build/pic/fuzz/corpus test/fuzz/decode-seeds
build/pic/fuzz/fuzz_http: test/fuzz/fuzz_http.c src/http.c src/http.h src/net.h
@mkdir -p $(@D)
$(FUZZ_CC) $(PIC_WARN) $(FUZZ_FLAGS) -Isrc -o $@ test/fuzz/fuzz_http.c src/http.c
fuzz-http: build/pic/fuzz/fuzz_http
@mkdir -p build/pic/fuzz/http-corpus build/pic/fuzz/findings
build/pic/fuzz/fuzz_http -max_total_time=$(FUZZ_SECONDS) -max_len=4096 -timeout=10 -dict=test/fuzz/http.dict \
-artifact_prefix=build/pic/fuzz/findings/http- build/pic/fuzz/http-corpus test/fuzz/http-seeds
build/pic/fuzz/fuzz_chat: test/fuzz/fuzz_chat.c src/openai_chat.c src/openai_chat.h src/sse.c src/sse.h build/pic/fuzz/sqlite3.o
$(FUZZ_CC) $(PIC_WARN) $(FUZZ_FLAGS) -Isrc -isystem $(PIC_VENDOR) -o $@ test/fuzz/fuzz_chat.c src/openai_chat.c src/sse.c \
build/pic/fuzz/sqlite3.o -lm -lpthread
fuzz-chat: build/pic/fuzz/fuzz_chat
@mkdir -p build/pic/fuzz/chat-corpus build/pic/fuzz/findings
build/pic/fuzz/fuzz_chat -max_total_time=$(FUZZ_SECONDS) -max_len=8192 -timeout=10 -dict=test/fuzz/sse.dict \
-artifact_prefix=build/pic/fuzz/findings/chat- build/pic/fuzz/chat-corpus test/fuzz/chat-seeds
build/pic/fuzz/fuzz_responses: test/fuzz/fuzz_responses.c src/openai_responses.c src/openai_responses.h src/sse.c src/sse.h \
build/pic/fuzz/sqlite3.o
$(FUZZ_CC) $(PIC_WARN) $(FUZZ_FLAGS) -Isrc -isystem $(PIC_VENDOR) -o $@ test/fuzz/fuzz_responses.c \
src/openai_responses.c src/sse.c build/pic/fuzz/sqlite3.o -lm -lpthread
fuzz-responses: build/pic/fuzz/fuzz_responses
@mkdir -p build/pic/fuzz/responses-corpus build/pic/fuzz/findings
build/pic/fuzz/fuzz_responses -max_total_time=$(FUZZ_SECONDS) -max_len=8192 -timeout=10 -dict=test/fuzz/sse.dict \
-artifact_prefix=build/pic/fuzz/findings/responses- build/pic/fuzz/responses-corpus test/fuzz/responses-seeds