summaryrefslogtreecommitdiff
path: root/tests/cli.cmake
blob: cc9601882fea3de72f012bb7cd95a6805849021a (plain)
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
if(NOT DEFINED SERVER OR NOT EXISTS "${SERVER}")
  message(FATAL_ERROR "SERVER does not name a built tiny-convmem-mcp executable")
endif()
if(NOT DEFINED IMPORT_INPUT OR NOT EXISTS "${IMPORT_INPUT}")
  message(FATAL_ERROR "IMPORT_INPUT does not name the import fixture")
endif()
if(NOT DEFINED DATA_DIR)
  message(FATAL_ERROR "DATA_DIR is required")
endif()

file(REMOVE_RECURSE "${DATA_DIR}")

# Import JSONL via CLI.
execute_process(
  COMMAND "${SERVER}" --data-dir "${DATA_DIR}" --import "${IMPORT_INPUT}"
  OUTPUT_VARIABLE import_output
  ERROR_VARIABLE import_error
  RESULT_VARIABLE import_result
)
if(NOT import_result EQUAL 0)
  message(FATAL_ERROR "CLI import failed: ${import_error}\n${import_output}")
endif()
if(NOT import_output MATCHES "\\{\"imported\":2,\"rejected\":0\\}")
  message(FATAL_ERROR "unexpected import result: ${import_output}")
endif()

# Export the same data via CLI.
set(export_path "${DATA_DIR}/exported.jsonl")
execute_process(
  COMMAND "${SERVER}" --data-dir "${DATA_DIR}" --export "${export_path}"
  OUTPUT_VARIABLE export_output
  ERROR_VARIABLE export_error
  RESULT_VARIABLE export_result
)
if(NOT export_result EQUAL 0)
  message(FATAL_ERROR "CLI export failed: ${export_error}\n${export_output}")
endif()

# Verify exported content includes the manifest and imported records.
file(READ "${export_path}" exported)
string(FIND "${exported}" "\"type\":\"tiny-convmem-manifest\"" manifest_position)
string(FIND "${exported}" "imported via CLI" first_position)
string(FIND "${exported}" "second imported message" second_position)
if(manifest_position EQUAL -1 OR first_position EQUAL -1 OR second_position EQUAL -1)
  message(FATAL_ERROR "exported JSONL missing expected records: ${exported}")
endif()

# Round-trip: re-import the exported file into a fresh store.
file(REMOVE_RECURSE "${DATA_DIR}/roundtrip")
execute_process(
  COMMAND "${SERVER}" --data-dir "${DATA_DIR}/roundtrip" --import "${export_path}"
  OUTPUT_VARIABLE roundtrip_output
  ERROR_VARIABLE roundtrip_error
  RESULT_VARIABLE roundtrip_result
)
if(NOT roundtrip_result EQUAL 0)
  message(FATAL_ERROR "CLI round-trip import failed: ${roundtrip_error}\n${roundtrip_output}")
endif()
if(NOT roundtrip_output MATCHES "\\{\"imported\":2,\"rejected\":0\\}")
  message(FATAL_ERROR "unexpected round-trip result: ${roundtrip_output}")
endif()

message(STATUS "CLI import/export round-trip succeeded")