diff options
Diffstat (limited to 'tests/cli.cmake')
| -rw-r--r-- | tests/cli.cmake | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/cli.cmake b/tests/cli.cmake new file mode 100644 index 0000000..cc96018 --- /dev/null +++ b/tests/cli.cmake @@ -0,0 +1,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")
\ No newline at end of file |
