diff options
| author | tanaka takashi <isazaka@gmail.com> | 2026-07-04 17:21:32 +0900 |
|---|---|---|
| committer | tanaka takashi <isazaka@gmail.com> | 2026-07-04 17:21:32 +0900 |
| commit | 0634f2048c7c9a474aab1d8104b964b3bf70a064 (patch) | |
| tree | 508c305a64cbd3b01f5146776e22865d283d5dbb /tests/cli.cmake | |
| parent | eb5e9d9f37bda7d78f69614da70402357794168a (diff) | |
feat(P1-002): migrate offline JSONL import/export to dedicated CLI
- Replace the MCP import_messages tool with standalone CLI commands:
iny-convmem-mcp --data-dir <path> --import <file>
iny-convmem-mcp --data-dir <path> --export <file>
- Add src/cli/{import,export,cli.h} and a CTest process test (tiny-convmem-mcp.cli)
covering round-trip, manifest generation, overwrite/reject policies, and
include_deleted export.
- Fix Debug heap corruption in iny_store_import() by deep-copying imported
messages instead of taking ownership of caller-allocated records, which were
later freed by the caller.
- Remove the now-redundant src/mcp/tools/import_messages.c and keep the tool
registry at 7 MCP tools.
- Update docs/development-plan.md (P1-002 complete) and
docs/implementation-status.md with CLI test coverage.
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 |
