feat: v0 — glpi-go client, mglpi CLI, mglpi-mcp, fake-GLPI test suite [#767]

https://projects.knownelement.com/issues/767#note-4191
This commit is contained in:
2026-09-04 08:41:25 -05:00
commit 5da1eee08f
26 changed files with 4956 additions and 0 deletions
Executable
+82
View File
@@ -0,0 +1,82 @@
#!/bin/sh
# mopac-glpi-go dev wrapper. EVERY compile/vet/test path routes through
# the digest-pinned Docker builder (same image as mopac-redmine-go and
# mopac-keyproxy; the host runs containers, never toolchains).
#
# Usage: ./dev.sh {build|vet|test|check|smoke|mglpi|mcp|shell} [args...]
#
# build compile ./cmd/mglpi and ./cmd/mglpi-mcp into bin/
# vet go vet ./...
# test go test ./... (all tests run against the in-process fake
# GLPI server; the real CMDB is NEVER contacted)
# check build + vet + test (the pre-push gate)
# smoke end-to-end smoke: builds, boots the fake GLPI in a
# container on 127.0.0.1:8602, drives the real CLI from the
# host through 0600 env files (change create/list/show/
# transition/followup round-trips, ci search, agent-profile
# switch, -o json, MCP handshake, redaction check on stderr),
# tears everything down
# mglpi run the real CLI: rebuilds bin/mglpi (static) if any source
# is newer, then runs it inside the digest-pinned builder with
# MGLPI_URL/MGLPI_APP_TOKEN/MGLPI_USER_TOKEN/MGLPI_PROFILE_ID
# passed through from the caller's env (the harness loop
# exports them from loop.env; humans export their own).
# HARNESS_DOCKER_NETWORK (optional) joins the run to a named
# network (e2e fakes).
# mcp same as mglpi but runs the stdio MCP server (bin/mglpi-mcp)
# shell interactive sh inside the builder
set -e
IMAGE="golang@sha256:e8c859f5632dcfde7b32d2012b4351728f6437930887c2f6a91ea242459e5514" # = golang:1.26-bookworm (bash present; alpine lacks it)
run() {
docker run --rm -v "$PWD:/h" -w /h \
-u "$(id -u):$(id -g)" -e HOME=/tmp -e GOFLAGS=-buildvcs=false \
"$IMAGE" "$@"
}
cmd=${1:-check}
shift || true
case "$cmd" in
build)
run sh -c 'go build -o bin/mglpi ./cmd/mglpi && go build -o bin/mglpi-mcp ./cmd/mglpi-mcp'
;;
vet)
run go vet ./...
;;
test)
run go test "$@" ./...
;;
check)
run sh -c 'go build -o bin/mglpi ./cmd/mglpi && go build -o bin/mglpi-mcp ./cmd/mglpi-mcp && go vet ./... && go test ./...'
;;
smoke)
./smoke/smoke.sh
;;
mglpi|mcp)
# Rebuild-if-stale (static: the loop container is musl), then run the
# binary in the builder. Its own docker run: -e passthrough must come
# before the image, which run() cannot do.
bin=bin/mglpi
pkg=./cmd/mglpi
[ "$cmd" = "mcp" ] && bin=bin/mglpi-mcp && pkg=./cmd/mglpi-mcp
if [ ! -x "$bin" ] || [ -n "$(find cmd internal glpi glpi_test.go go.mod -newer "$bin" -print -quit 2>/dev/null)" ]; then
echo "dev.sh: $bin missing or stale -> static rebuild" >&2
run env CGO_ENABLED=0 go build -o "$bin" "$pkg"
fi
NET=""
if [ -n "$HARNESS_DOCKER_NETWORK" ]; then NET="--network $HARNESS_DOCKER_NETWORK"; fi
docker run --rm -i ${NET:+"$NET"} -v "$PWD:/h" -w /h \
-u "$(id -u):$(id -g)" -e HOME=/tmp \
-e MGLPI_URL -e MGLPI_APP_TOKEN -e MGLPI_USER_TOKEN -e MGLPI_PROFILE_ID \
"$IMAGE" "./$bin" "$@"
;;
shell)
run sh
;;
*)
echo "dev.sh: unknown command $cmd (build|vet|test|check|smoke|mglpi|mcp|shell)" >&2
exit 1
;;
esac