|
| 1 | +#!/usr/bin/env bash |
| 2 | +# SPDX-FileCopyrightText: Sudo Apt Holdings LLC |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | +# The chat on the test registry (the fake provider, the test tools, a scripted turn that calls |
| 5 | +# the write-risk tool) for the slice 021 screenshots and the owner's manual queue. The test |
| 6 | +# environment's Repo without its sandbox pool and with the check_origin off, the application |
| 7 | +# started by hand; the port is printed as PORT=<n>. Run `mix assets.build` first, and remove |
| 8 | +# any stale `priv/static/assets/**/*.gz` (Plug.Static serves the gzip in this environment). |
| 9 | +# Its database is trinity_screenshots.db, never the test suite's: rows written outside the |
| 10 | +# sandbox broke four usage_events tests once (slice 021 NOTES). |
| 11 | +cd "$(dirname "$0")/.." |
| 12 | +export MIX_ENV=test |
| 13 | +exec systemd-run --user --scope -p MemoryMax=32G --quiet -- mix run --no-start --no-halt -e ' |
| 14 | +repo = Application.get_env(:trinity, Trinity.Repo) |> Keyword.delete(:pool) |> Keyword.put(:database, "trinity_screenshots.db") |
| 15 | +Application.put_env(:trinity, Trinity.Repo, repo) |
| 16 | +endpoint = Application.get_env(:trinity, TrinityWeb.Endpoint) |> Keyword.put(:check_origin, false) |
| 17 | +Application.put_env(:trinity, TrinityWeb.Endpoint, endpoint) |
| 18 | +Application.put_env(:trinity, :permissions, expiry_ms: 600_000, session_grant_ms: 3_600_000) |
| 19 | +# The suite sets tools timeout_ms: 2_000, right for tests and impossible for a person: an approval |
| 20 | +# that waits on a human always expires and the turn records the tool as timed out. A minute here. |
| 21 | +tools = Application.get_env(:trinity, :tools, []) |
| 22 | +Application.put_env(:trinity, :tools, Keyword.put(tools, :timeout_ms, 60_000)) |
| 23 | +# Migrate before the application starts, not after. Oban is a supervised child and its tables |
| 24 | +# must exist by the time it boots; running the migrator afterwards only ever appeared to work |
| 25 | +# because a previous run had left a migrated file behind, and it fails outright on a fresh one. |
| 26 | +for repo <- [Trinity.Repo, Trinity.Repo.Receipts] do |
| 27 | + {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) |
| 28 | +end |
| 29 | +{:ok, _} = Application.ensure_all_started(:trinity) |
| 30 | +call = [{:text_delta, "I will save that as a note. "}, {:sleep, 300}, {:tool_call_start, "c1", "write_note"}, {:tool_call_end, "c1", %{"path" => "/home/me/notes/today.md", "text" => "Buy oat milk, call the dentist, finish the slice."}}, {:usage, %{input_tokens: 12, output_tokens: 20}}, {:done, :tool_calls}] |
| 31 | +final = fn text -> Enum.flat_map(String.split(text), &[{:text_delta, &1 <> " "}, {:sleep, 40}]) ++ [{:usage, %{input_tokens: 40, output_tokens: 30}}, {:done, :stop}] end |
| 32 | +# The pair repeated: each capture run consumes one call and one answer, and a second run on the |
| 33 | +# same server otherwise gets an empty script and a turn that ends instantly at idle. |
| 34 | +answer = final.("Saved. The note is at **/home/me/notes/today.md** with three items: oat milk, the dentist, and the slice.") |
| 35 | +Trinity.LLM.Providers.Fake.scripts(Enum.concat(List.duplicate([call, answer], 6))) |
| 36 | +{:ok, {_, port}} = TrinityWeb.Endpoint.server_info(:http) |
| 37 | +IO.puts("PORT=#{port}") |
| 38 | +' |
0 commit comments