1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
-- luacheck: globals describe it assert
local _99 = require("99")
local Tracking = require("99.state.tracking")
local test_utils = require("99.test.test_utils")
local eq = assert.are.same
local function run(provider, operation, status, prompt)
_99[operation]({ additional_prompt = prompt })
provider:resolve(status, "result")
end
describe("tracking", function()
it("serializes requests based on configured counts", function()
local previous_counts = vim.deepcopy(Tracking.__config.serialize_count)
Tracking.setup({
serialize_counts = {
vibe = 1,
search = 1,
tutorial = 3,
visual = 0,
},
})
local provider = test_utils.TestProvider.new()
_99.setup(test_utils.get_test_setup_options({
in_flight_options = { enable = false },
}, provider))
test_utils.create_file({ "local value = 1" }, "lua", 1, 0)
run(provider, "search", "success", "search one")
run(provider, "search", "success", "search two")
run(provider, "vibe", "success", "vibe one")
run(provider, "vibe", "success", "vibe two")
run(provider, "tutorial", "success", "tutorial one")
run(provider, "tutorial", "success", "tutorial two")
run(provider, "tutorial", "success", "tutorial three")
run(provider, "tutorial", "success", "tutorial four")
run(provider, "search", "failed", "search failed")
local serialized = _99.__get_state().tracking:serialize()
local actual_counts = {
search = 0,
vibe = 0,
tutorial = 0,
visual = 0,
}
for _, request in ipairs(serialized.requests) do
actual_counts[request.data.type] = actual_counts[request.data.type] + 1
end
eq(1, actual_counts.search)
eq(1, actual_counts.vibe)
eq(3, actual_counts.tutorial)
eq(0, actual_counts.visual)
eq(5, #serialized.requests)
Tracking.__config.serialize_count = previous_counts
end)
it("successful returns things in reverse order", function()
local provider = test_utils.TestProvider.new()
_99.setup(test_utils.get_test_setup_options({
in_flight_options = { enable = false },
}, provider))
test_utils.create_file({ "local value = 1" }, "lua", 1, 0)
run(provider, "search", "success", "first success")
run(provider, "search", "failed", "failed request")
run(provider, "vibe", "success", "second success")
run(provider, "tutorial", "success", "third success")
local successful = _99.__get_state().tracking:successful()
eq(3, #successful)
eq("third success", successful[1].user_prompt)
eq("second success", successful[2].user_prompt)
eq("first success", successful[3].user_prompt)
end)
end)
|