Artifact 4da90f4eeb29b6c4a6c508fff4792806c18fe5aa4c9afca4dc2cd6151fc78a23:
- File
Makefile
— part of check-in
[c8bc1bfa6d]
at
2026-11-23 11:40:21
on branch ux-models
— Model choice says why and recovers from a refused key
With no saved default, pic starts on a provider whose key worked and passes over one that was refused, out of credit or limited; OpenRouter, Moonshot and DeepSeek start on inexpensive general models. The first screen (and stderr for ask and -p) names the model and why; with no key it says how to get one. The picker shows prices and key marks, lists keyless models once typed, ranks exact and prefix matches first, says what it saved and when the thinking level changes. After a refused key, Alt+P picks another model and the message returns to the editor for it. pic sessions shows each conversation's model and marks failed ones; pic models --json carries key; pic --version; pic help start opens with the user path. (user: dmestas, size: 35277) [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-webpush test-files test-models test-userdb test-cred test-keyhealth test-noise 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/filelog.c src/rewind.c src/listings.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/inbox.c src/attach.c src/noise.c src/remote.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/tui/remote.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/keyhealth.c src/keyprobe.c src/oauth.c src/oauth_openai.c src/oauth_openrouter.c src/webpush.c \
src/models.c src/transform.c src/help.c src/main.c
# Everything the generated pic.c is made from besides the .c list: every internal header and .inc.
# The wildcard misses the two generated .inc on a clean tree, so they are named.
PIC_HDR := $(wildcard src/*.h src/tui/*.h src/*.inc src/tui/*.inc) src/changelog.inc src/manual.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. pic.c lists it as a
# prerequisite, so a clean tree builds it first.
src/changelog.inc: CHANGELOG.md tools/changelog-inc.sh
sh tools/changelog-inc.sh CHANGELOG.md > [email protected] && mv -f [email protected] $@
# pic help's topics: docs/manual and docs/reference, compiled in the same way.
src/manual.inc: $(wildcard docs/manual/*.md docs/reference/*.md) tools/manual-inc.sh
sh tools/manual-inc.sh > [email protected] && mv -f [email protected] $@
# The release bundle: pic.c (all of pic's sources as one translation unit) beside the vendored
# dependency sources, built with one plain cc line (docs/dev/amalgamation.md). VERSION is the
# newest CHANGELOG date.
PIC_AMAL_VERSION ?= $(shell awk '/^\#\# [0-9]/ { gsub(/[^0-9]/, "", $$2); print $$2; exit }' CHANGELOG.md)
PIC_AMAL_NAME := pic-amalgamation-$(PIC_AMAL_VERSION)
PIC_AMAL_OUT := build/amalgamation
PIC_AMAL_RUNS := crash print tools
.PHONY: amalgamation test-amal amalgam-names $(PIC_AMAL_RUNS:%=run-amal-%)
amalgamation: src/changelog.inc src/manual.inc
sh tools/amalgamation.sh $(PIC_AMAL_OUT) $(PIC_AMAL_NAME) $(PIC_SRC)
$(PIC_AMAL_OUT)/$(PIC_AMAL_NAME).tar.gz: $(PIC_SRC) $(PIC_HDR) tools/amalgamate.sh tools/amalgamation.sh $(wildcard vendor/*/*.[ch] vendor/bearssl/*/*.[ch] vendor/bearssl/src/*/*.[ch])
$(MAKE) amalgamation
# The tarball, unpacked and built with the README's own cc line, then a slice of the suite
# against that binary: crash and recovery, print mode and the tools.
$(PIC_AMAL_OUT)/test/pic: $(PIC_AMAL_OUT)/$(PIC_AMAL_NAME).tar.gz
rm -rf $(PIC_AMAL_OUT)/test && mkdir -p $(PIC_AMAL_OUT)/test
tar -C $(PIC_AMAL_OUT)/test -xzf $<
cd $(PIC_AMAL_OUT)/test/$(PIC_AMAL_NAME) && sh -c "$$(sed -n 's/^ \(cc .*\)$$/\1/p' README)" && mv pic ../pic
PIC_AMAL_ENV := PIC="$(CURDIR)/$(PIC_AMAL_OUT)/test/pic" SERVER="$(CURDIR)/build/pic/fake_server" DRIVE="$(CURDIR)/build/pic/pty_drive"
$(PIC_AMAL_RUNS:%=run-amal-%): run-amal-%: $(PIC_AMAL_OUT)/test/pic build/pic/fake_server build/pic/pty_drive build/pic/sqlite3
@$(PIC_RUN) amal-$* $(PIC_AMAL_ENV) sh test/pic/$*.sh $(if $(filter print,$*),,--no-faults)
# The names check and the bundle's slice; test-pic runs both.
test-amal: amalgam-names $(PIC_AMAL_RUNS:%=run-amal-%)
amalgam-names: src/changelog.inc src/manual.inc
@$(PIC_RUN) amal-names sh test/pic/amalgam.sh $(PIC_SRC)
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 -isystem vendor/qrcodegen -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 $@ $<
# Nayuki's QR Code generator (vendor/qrcodegen): the QR code /remote-control draws.
build/pic/release/vendor/qrcodegen/%.o: vendor/qrcodegen/%.c
@mkdir -p $(@D)
$(CC) -O2 -w -c -o $@ $<
build/pic/dev/vendor/qrcodegen/%.o: vendor/qrcodegen/%.c
@mkdir -p $(@D)
$(CC) $(PIC_SAN) -w -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) build/pic/release/vendor/qrcodegen/qrcodegen.o
PIC_DEV_V := build/pic/dev/vendor/sqlite3.o build/pic/dev/vendor/libfossil.o \
$(PIC_ZLIB:%=build/pic/dev/vendor/zlib/%.o) build/pic/dev/vendor/qrcodegen/qrcodegen.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 code is one generated translation unit per flavor, made by the generator the release
# bundle uses (docs/dev/amalgamation.md). Dev's has #line markers, so compiler errors, sanitizer
# traces and a debugger name src/FILE.c:LINE; release's has none. Dev adds the sanitizers and
# crash points; release has neither. The unit depends on every source, header and .inc.
build/pic/release/pic.c: $(PIC_SRC) $(PIC_HDR) tools/amalgamate.sh
@mkdir -p $(@D)
sh tools/amalgamate.sh $(PIC_SRC) > [email protected] && mv -f [email protected] $@
build/pic/dev/pic.c: $(PIC_SRC) $(PIC_HDR) tools/amalgamate.sh
@mkdir -p $(@D)
sh tools/amalgamate.sh -l $(PIC_SRC) > [email protected] && mv -f [email protected] $@
# The same without main.c, for the tests and the benchmark that bring their own main.
PIC_LIB_SRC := $(filter-out src/main.c,$(PIC_SRC))
build/pic/release/pic-lib.c: $(PIC_SRC) $(PIC_HDR) tools/amalgamate.sh
@mkdir -p $(@D)
sh tools/amalgamate.sh $(PIC_LIB_SRC) > [email protected] && mv -f [email protected] $@
build/pic/dev/pic-lib.c: $(PIC_SRC) $(PIC_HDR) tools/amalgamate.sh
@mkdir -p $(@D)
sh tools/amalgamate.sh -l $(PIC_LIB_SRC) > [email protected] && mv -f [email protected] $@
# Kept after a build: the unit is what a debugger and a compiler error read.
.PRECIOUS: build/pic/release/pic.c build/pic/dev/pic.c build/pic/release/pic-lib.c build/pic/dev/pic-lib.c
build/pic/dev/%.o: build/pic/dev/%.c
$(CC) $(PIC_WARN) $(PIC_SAN) -DPIC_FAULTS $(PIC_INC) $(PIC_NET_INC) -c -o $@ $<
build/pic/release/%.o: build/pic/release/%.c
$(CC) $(PIC_WARN) -O2 $(PIC_INC) $(PIC_NET_INC) -c -o $@ $<
# Benchmarks run on release-flag objects, so they measure what users run.
build/pic/pic_bench: bench/pic_bench.c build/pic/release/pic-lib.o $(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 build/pic/release/pic-lib.o \
$(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
build/pic/fake_oauth: test/pic/fake_oauth.c
@mkdir -p $(@D)
$(CC) -std=c11 -Wall -Wextra -Werror -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE -O1 -o $@ test/pic/fake_oauth.c
# The sign-in machinery against the fake authorization server: PKCE, the callback's state check,
# a pasted redirect, the device-code poll. A HOME of its own.
PIC_OAUTH_UNITS := src/oauth.c src/oauth_openai.c src/oauth_openrouter.c src/cred.c src/userdb.c src/sqlar.c src/http.c src/net.c src/input.c src/platform.c
build/pic/dev/test_oauth: test/pic/test_oauth.c $(PIC_OAUTH_UNITS) src/oauth.h src/cred.h src/userdb.h src/http.h src/net.h \
src/ca_bundle.inc $(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) -DPIC_FAULTS $(PIC_INC) $(PIC_NET_INC) -o $@ test/pic/test_oauth.c $(PIC_OAUTH_UNITS) \
$(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
test-oauth: build/pic/dev/test_oauth build/pic/fake_oauth
rm -rf build/pic/oauth-home && mkdir -p build/pic/oauth-home
HOME="$(CURDIR)/build/pic/oauth-home" FAKE_OAUTH="$(CURDIR)/build/pic/fake_oauth" build/pic/dev/test_oauth \
test/pic/responses-streams/reasoning_text.sse
test-http: build/pic/dev/test_http
build/pic/dev/test_http
build/pic/dev/test_webpush: test/pic/test_webpush.c src/webpush.c src/webpush.h src/noise.c src/noise.h $(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_webpush.c src/webpush.c src/noise.c $(PIC_NET) \
build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
test-webpush: build/pic/dev/test_webpush build/pic/fake_server
build/pic/dev/test_webpush build/pic/fake_server "$(CURDIR)/build/pic/webpush-work"
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 src/userdb.c src/userdb.h src/procs.c src/sqlar.c $(PIC_DEV_V)
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) $(PIC_INC) -o $@ test/pic/test_skills.c src/skills.c src/ignore.c src/prompts.c src/input.c src/platform.c src/userdb.c src/procs.c src/sqlar.c $(PIC_DEV_V) $(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 build/pic/dev/pic-lib.o $(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 build/pic/dev/pic-lib.o \
$(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
# A toy provider adapter registered through provider_http.h alone (docs/dev/providers.md).
build/pic/dev/test_adapter: test/pic/test_adapter.c build/pic/dev/pic-lib.o $(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_adapter.c build/pic/dev/pic-lib.o \
$(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
test-adapter: build/pic/dev/test_adapter
ASAN_OPTIONS=detect_leaks=0 build/pic/dev/test_adapter
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)
# The loopback relay and the scripted phone that test/pic/remote.sh drives pic remote with.
build/pic/fake_relay: test/pic/fake_relay.c src/noise.c src/noise.h src/platform.c src/input.c $(PIC_REL_V) build/pic/release/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_WARN) -O1 $(PIC_INC) $(PIC_NET_INC) -o $@ test/pic/fake_relay.c src/noise.c src/platform.c src/input.c \
$(PIC_REL_V) build/pic/release/vendor/libbearssl.a $(PIC_LIBS)
build/pic/fake_phone: test/pic/fake_phone.c src/noise.c src/noise.h $(PIC_NET) src/sse.c src/sse.h $(PIC_REL_V) build/pic/release/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_WARN) -O1 $(PIC_INC) $(PIC_NET_INC) -o $@ test/pic/fake_phone.c src/noise.c src/sse.c $(PIC_NET) \
$(PIC_REL_V) build/pic/release/vendor/libbearssl.a $(PIC_LIBS)
run-remote-dev run-remote-rel: build/pic/fake_relay build/pic/fake_phone
# pic remote against the real relay Worker under wrangler dev (a pic-relay checkout, PIC_RELAY_DIR,
# default ~/pic-relay), local only; skipped without node or wrangler. Dev build: its passphrase seam.
# pic remote under faults against the test relay (relay and pic remote killed, the network
# dropped, the stream silent, pic remote stopped): every command once, every event in order.
run-remote-soak-dev: build/pic/dev/pic build/pic/fake_server build/pic/fake_relay build/pic/fake_phone build/pic/sqlite3
@$(PIC_RUN) remote-soak-dev $(PIC_DEV_ENV) SQLITE3="$(CURDIR)/build/pic/sqlite3" sh test/pic/remote-soak.sh
# The checkout is found from the real HOME, read when the Makefile is: the tests' HOME is private.
PIC_RELAY_DIR := $(if $(PIC_RELAY_DIR),$(PIC_RELAY_DIR),$(HOME)/pic-relay)
# node itself, found now: a version manager's shim reads its trust from the real HOME.
PIC_NODE := $(if $(PIC_NODE),$(PIC_NODE),$(shell node -p process.execPath 2> /dev/null))
run-remote-interop-dev: build/pic/dev/pic build/pic/fake_server build/pic/fake_phone build/pic/sqlite3
@$(PIC_RUN) remote-interop-dev $(PIC_DEV_ENV) SQLITE3="$(CURDIR)/build/pic/sqlite3" PIC_RELAY_DIR="$(PIC_RELAY_DIR)" PIC_NODE="$(PIC_NODE)" \
sh test/pic/remote-interop.sh
# Remote control's cryptography against the shared vectors (docs/design/remote-protocol.md).
build/pic/dev/test_noise: test/pic/test_noise.c src/noise.c src/noise.h 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_noise.c src/noise.c src/input.c src/platform.c \
$(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a $(PIC_LIBS)
test-noise: build/pic/dev/test_noise
build/pic/dev/test_noise test/pic/remote-vectors.json
# A HOME of its own: the store test needs a pic.sqlite with no credentials.
build/pic/dev/test_keyhealth: test/pic/test_keyhealth.c src/keyhealth.c src/keyhealth.h src/cred.h
@mkdir -p $(@D)
$(CC) $(PIC_WARN) $(PIC_SAN) -Isrc -o $@ test/pic/test_keyhealth.c src/keyhealth.c
test-keyhealth: build/pic/dev/test_keyhealth
TZ=UTC build/pic/dev/test_keyhealth
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: build/pic/release/pic.o $(PIC_REL_V) build/pic/release/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) -O2 -o $@ build/pic/release/pic.o $(PIC_REL_V) build/pic/release/vendor/libbearssl.a $(PIC_LIBS)
build/pic/dev/pic: build/pic/dev/pic.o $(PIC_DEV_V) build/pic/dev/vendor/libbearssl.a
@mkdir -p $(@D)
$(CC) $(PIC_SAN) -o $@ build/pic/dev/pic.o $(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-amal $(PIC_AMAL_RUNS:%=run-amal-%) test-pic test-pic-run test-sqlite3 test-sse test-tui test-highlight test-decode test-http test-webpush test-files test-models test-userdb test-cred test-keyhealth test-oauth test-xfer test-prompts test-skills test-hooks test-adapter test-provider bench-pic bench-pic-record: export HOME := $(CURDIR)/build/pic
test-amal $(PIC_AMAL_RUNS:%=run-amal-%) test-pic test-pic-run test-sqlite3 test-sse test-tui test-highlight test-decode test-http test-webpush 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-amal $(PIC_AMAL_RUNS:%=run-amal-%) test-pic test-pic-run test-sqlite3 test-sse test-tui test-highlight test-decode test-http test-webpush 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-amal $(PIC_AMAL_RUNS:%=run-amal-%) test-pic test-pic-run test-sqlite3 test-sse test-tui test-highlight test-decode test-http test-webpush 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" RELAY="$(CURDIR)/build/pic/fake_relay" PHONE="$(CURDIR)/build/pic/fake_phone" SERVER="$(CURDIR)/build/pic/fake_server" DRIVE="$(CURDIR)/build/pic/pty_drive" OAUTH="$(CURDIR)/build/pic/fake_oauth"
PIC_REL_ENV := PIC="$(CURDIR)/build/pic/release/pic" RELAY="$(CURDIR)/build/pic/fake_relay" PHONE="$(CURDIR)/build/pic/fake_phone" SERVER="$(CURDIR)/build/pic/fake_server" DRIVE="$(CURDIR)/build/pic/pty_drive" OAUTH="$(CURDIR)/build/pic/fake_oauth"
# 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 replies:test/tui/replies.sh \
provider!:test/pic/provider.sh bench!:test/pic/bench.sh ps:test/pic/ps.sh print:test/pic/print.sh modelchoice:test/pic/modelchoice.sh toolset:test/pic/toolset.sh \
creds!:test/pic/creds.sh keys!:test/pic/keys.sh probes!:test/pic/probes.sh keyprompt!:test/tui/keyprompt.sh keyprobe:test/tui/keyprobe.sh modelpick:test/tui/modelchoice.sh oauth!:test/pic/oauth.sh rpc:test/pic/rpc.sh help:test/pic/help.sh parallel!:test/pic/parallel.sh shared!:test/pic/shared.sh \
rewind!:test/pic/rewind.sh grapevine!:test/pic/grapevine.sh remote!:test/pic/remote.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/fake_oauth build/pic/pty_drive build/pic/sqlite3 build/pic/fake_relay build/pic/fake_phone
@$$(PIC_RUN) $(1)-dev $$(PIC_DEV_ENV) sh $(2)
run-$(1)-rel: build/pic/release/pic build/pic/fake_server build/pic/fake_oauth build/pic/pty_drive build/pic/sqlite3 build/pic/fake_relay build/pic/fake_phone
@$$(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) run-remote-interop-dev run-remote-soak-dev test-pic-run
test-pic:
@rm -rf $(PIC_LOGDIR) && mkdir -p $(PIC_LOGDIR)
$(MAKE) -k -j$(JOBS) test-pic-run PIC_RELAY_DIR="$(PIC_RELAY_DIR)" PIC_NODE="$(PIC_NODE)"
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).
# Check 5 links the core files alone with the vendored libraries (docs/dev/tiers.md).
test-docs: export TIERS_CORE_LINK := $(PIC_REL_V) build/pic/release/vendor/libbearssl.a $(PIC_LIBS)
test-docs: export TIERS_LINK_ROOT := $(CURDIR)
test-docs: $(PIC_REL_V) build/pic/release/vendor/libbearssl.a build/pic/release/pic
sh test/pic/docs.sh
sh test/pic/tiers.sh
sh test/pic/tiers.sh --selftest
test-pic-run: test-docs test-amal test-sse test-tui test-highlight test-decode test-http test-webpush test-files test-models test-userdb test-cred test-keyhealth test-noise test-oauth test-xfer test-prompts test-skills test-hooks test-adapter test-sqlite3 $(PIC_RUN_TARGETS) run-remote-interop-dev run-remote-soak-dev
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/tui/remote.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 build/pic/dev/vendor/qrcodegen/qrcodegen.o src/tui/remote.h 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) -isystem vendor/qrcodegen -o $@ test/tui/test_tui.c $(PIC_TUI_UNITS) build/pic/dev/vendor/sqlite3.o \
build/pic/dev/vendor/qrcodegen/qrcodegen.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