local base_url = std.env.get("ANTHROPIC_BASE_URL_TEST")
assert(base_url, "ANTHROPIC_BASE_URL_TEST must be set")
local target_path = std.env.get("COMPILE_LOOP_RANGE_TARGET")
assert(target_path, "COMPILE_LOOP_RANGE_TARGET must be set")
do
local f = assert(io.open(target_path, "w"))
for i = 1, 9 do
f:write(string.format("-- pre-range line %d\n", i))
end
for i = 10, 20 do
f:write(string.format("-- verbatim-line-%02d\n", i))
end
for i = 21, 599 do
f:write(string.format("-- padding line %03d\n", i))
end
f:write("-- marker: REPLACE_ME\n")
f:close()
end
local compile_loop = require("compile_loop")
local runner_call_count = 0
local function mock_runner(paths)
runner_call_count = runner_call_count + 1
local path = type(paths) == "table" and paths[1] or paths
local f = io.open(path, "r")
if not f then
return {ok=false, stderr="cannot open " .. tostring(path), stdout="", exit_code=1}
end
local content = f:read("*a") or ""
f:close()
if content:find("DONE", 1, true) then
return {ok=true, stdout="DONE marker found", stderr="", exit_code=0}
end
return {ok=false, stderr="DONE marker not found in file", stdout="", exit_code=1}
end
local td = compile_loop.make({
runner = mock_runner,
edit_mode = "diff",
llm = {
provider = "anthropic",
base_url = base_url,
api_key = "dummy",
model = "mock-model",
},
})
local result_json = td.handler({
spec = "apply REPLACE_ME → DONE using read_file_range for verbatim access",
target_files = { target_path },
})
local result = std.json.decode(result_json)
assert(result.ok,
"compile_loop must succeed with read_file_range verbatim access, got: "
.. tostring(result.summary or "?"))
print("READ_FILE_RANGE_VERBATIM_PASS")