Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.163
1.0.164
21 changes: 21 additions & 0 deletions lib/optimal_system_agent/agent/run_store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,27 @@ defmodule OptimalSystemAgent.Agent.RunStore do
Application.get_env(:optimal_system_agent, :agent_runs_dir) || default_runs_dir()
end

@doc """
Clear all in-memory run state: the runs, tree-edge, and lease-owner tables.

Test support. RunStore's ETS tables are process-global and outlive a single
test, so a run started by one test stays visible to the next — which flakes
order-dependent assertions (e.g. "an unknown agent id → No run found" seeing a
leftover run). Call this in `setup` for hermetic run-store tests (mirrors
`Tools.FileState.reset/0`). (#208)
"""
@spec reset() :: :ok
def reset do
ensure_table()
ensure_lease_table()
:ets.delete_all_objects(@table)
:ets.delete_all_objects(@edges_table)
:ets.delete_all_objects(@lease_owners)
:ok
rescue
ArgumentError -> :ok
end

defp ensure_table do
case :ets.whereis(@table) do
:undefined ->
Expand Down
2 changes: 1 addition & 1 deletion priv/rust/tui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion priv/rust/tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "osa-tui"
# `config::version_source_tests` fails the build if they diverge. This literal is
# only ever a last-resort fallback: build.rs prefers $OSA_VERSION (release CI),
# then the VERSION file.
version = "1.0.163"
version = "1.0.164"
edition = "2021"

[[bin]]
Expand Down
21 changes: 21 additions & 0 deletions test/agent/context_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ defmodule OptimalSystemAgent.Agent.ContextTest do

alias OptimalSystemAgent.Agent.Context

# Every test starts from a clean :default_provider. It is a process-global
# Application env that this file's "provider-specific system message format"
# describe (and other test files) set to :anthropic. A leaked non-plain-prefix
# provider makes build/1 route the runtime block through the cached system
# prompt and drop the current session id — which flaked "contains session id"
# in the full suite while it passed in isolation. Reset per test; describes
# that need a specific provider still set it themselves after this. (#208)
setup do
prev_provider = Application.get_env(:optimal_system_agent, :default_provider)
Application.delete_env(:optimal_system_agent, :default_provider)

on_exit(fn ->
case prev_provider do
nil -> Application.delete_env(:optimal_system_agent, :default_provider)
v -> Application.put_env(:optimal_system_agent, :default_provider, v)
end
end)

:ok
end

# ---------------------------------------------------------------------------
# Minimal valid state fixture
# ---------------------------------------------------------------------------
Expand Down
18 changes: 14 additions & 4 deletions test/agent/scratchpad_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@ defmodule OptimalSystemAgent.Agent.ScratchpadTest do
# default the decision table describes) for the duration. `async: false`
# because this mutates global application env.
setup do
prev = Application.get_env(:optimal_system_agent, :ollama_think)
# Start each test from a clean global scratchpad/provider config. Both keys
# are process-global Application env; a sibling test (or another file)
# leaving :scratchpad_enabled set flipped the `refute inject?(:anthropic)`
# cases to true in the full suite while they passed in isolation. Save,
# clear, and restore both so the module is hermetic. (#208)
prev_think = Application.get_env(:optimal_system_agent, :ollama_think)
prev_scratch = Application.get_env(:optimal_system_agent, :scratchpad_enabled)
Application.delete_env(:optimal_system_agent, :ollama_think)
Application.delete_env(:optimal_system_agent, :scratchpad_enabled)

on_exit(fn ->
case prev do
nil -> Application.delete_env(:optimal_system_agent, :ollama_think)
v -> Application.put_env(:optimal_system_agent, :ollama_think, v)
restore = fn
key, nil -> Application.delete_env(:optimal_system_agent, key)
key, v -> Application.put_env(:optimal_system_agent, key, v)
end

restore.(:ollama_think, prev_think)
restore.(:scratchpad_enabled, prev_scratch)
end)

:ok
Expand Down
7 changes: 7 additions & 0 deletions test/tools/builtins/task_wait_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ defmodule OptimalSystemAgent.Tools.Builtins.TaskWaitTest do
alias OptimalSystemAgent.Tools.UseContext

setup do
# Start from a clean global RunStore. Its ETS tables are process-global and
# outlive a test, so runs from sibling/other tests (e.g. the incomplete
# agent:p:neverdone / agent:p:stuck runs created here) leaked into the
# "unknown agent id -> No run found" join and flaked it in the full suite.
# (#208)
OptimalSystemAgent.Agent.RunStore.reset()

tmp = Path.join(System.tmp_dir!(), "osa_task_wait_#{System.unique_integer([:positive])}")
File.mkdir_p!(tmp)
prev = Application.get_env(:optimal_system_agent, :agent_runs_dir)
Expand Down
10 changes: 10 additions & 0 deletions test/tools/file_read_diagnostics_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,16 @@ defmodule OptimalSystemAgent.Tools.Builtins.FileReadDiagnosticsTest do
assert out == "curriculum vitae" <> eof_stamp(1)
end

# Skipped on non-macOS. On Linux the NFD filename is stored on disk as-is
# (macOS normalizes), so the rescued read records under the resolved path
# while check_read is queried with the NFD form and they mismatch —
# deterministically red on Linux CI (never a flake). Real fix (unicode-
# canonical FileState path-keying) is tracked in #212; the test still runs on
# macOS, where the on-disk path resolves to the NFD form.
unless match?({:unix, :darwin}, :os.type()) do
@tag skip: "#212: FileState NFD path-keying mismatch on Linux"
end

test "a rescued read is recorded so a follow-up edit is not blocked", %{tmp: tmp} do
# The read-before-edit ledger keys on the resolved path; if the rescue and
# the ledger disagreed, the caller would read successfully and then be told
Expand Down
Loading