@@ -119,8 +119,12 @@ with open(sys.argv[1], "w") as f:
119119 f.write("}\n")
120120GENEOF
121121
122- # Index
123- RESULT=$( cli index_repository " {\" repo_path\" :\" $TMPDIR \" }" )
122+ # Index (flag form: --repo-path -> repo_path)
123+ if ! RESULT=$( cli index_repository --repo-path " $TMPDIR " ) ; then
124+ echo " FAIL: index_repository (flag form) exited non-zero"
125+ cat " $CLI_STDERR "
126+ exit 1
127+ fi
124128echo " $RESULT "
125129
126130# Allocator-integrity guard: the prod binary overrides the global allocator with
@@ -166,7 +170,9 @@ echo "=== Phase 3: verify queries ==="
166170# 3a: search_graph — find the compute function
167171PROJECT=$( echo " $RESULT " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(d.get('project',''))" 2> /dev/null || echo " " )
168172
169- SEARCH=$( cli search_graph " {\" project\" :\" $PROJECT \" ,\" name_pattern\" :\" compute\" }" )
173+ if ! SEARCH=$( cli search_graph --project " $PROJECT " --name-pattern compute) ; then
174+ echo " FAIL: search_graph (flag form) exited non-zero" ; cat " $CLI_STDERR " ; exit 1
175+ fi
170176TOTAL=$( echo " $SEARCH " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(d.get('total',0))" 2> /dev/null || echo " 0" )
171177if [ " $TOTAL " -lt 1 ]; then
172178 echo " FAIL: search_graph for 'compute' returned 0 results"
175181echo " OK: search_graph found $TOTAL result(s) for 'compute'"
176182
177183# 3b: trace_path — verify compute has callers
178- TRACE=$( cli trace_path " {\" project\" :\" $PROJECT \" ,\" function_name\" :\" compute\" ,\" direction\" :\" inbound\" ,\" depth\" :1}" )
184+ if ! TRACE=$( cli trace_path --project " $PROJECT " --function-name compute --direction inbound --depth 1) ; then
185+ echo " FAIL: trace_path (flag form) exited non-zero" ; cat " $CLI_STDERR " ; exit 1
186+ fi
179187CALLERS=$( echo " $TRACE " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(len(d.get('callers',[])))" 2> /dev/null || echo " 0" )
180188if [ " $CALLERS " -lt 1 ]; then
181189 echo " FAIL: trace_path found 0 callers for 'compute'"
184192echo " OK: trace_path found $CALLERS caller(s) for 'compute'"
185193
186194# 3c: get_graph_schema — verify labels exist
187- SCHEMA=$( cli get_graph_schema " {\" project\" :\" $PROJECT \" }" )
195+ if ! SCHEMA=$( cli get_graph_schema --project " $PROJECT " ) ; then
196+ echo " FAIL: get_graph_schema (flag form) exited non-zero" ; cat " $CLI_STDERR " ; exit 1
197+ fi
188198LABELS=$( echo " $SCHEMA " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(len(d.get('node_labels',[])))" 2> /dev/null || echo " 0" )
189199if [ " $LABELS " -lt 3 ]; then
190200 echo " FAIL: schema has fewer than 3 node labels"
193203echo " OK: schema has $LABELS node labels"
194204
195205# 3d: Verify __init__.py didn't clobber Folder node
196- FOLDERS=$( cli search_graph " {\" project\" :\" $PROJECT \" ,\" label\" :\" Folder\" }" )
206+ if ! FOLDERS=$( cli search_graph --project " $PROJECT " --label Folder) ; then
207+ echo " FAIL: search_graph --label Folder exited non-zero" ; cat " $CLI_STDERR " ; exit 1
208+ fi
197209FOLDER_COUNT=$( echo " $FOLDERS " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(d.get('total',0))" 2> /dev/null || echo " 0" )
198210if [ " $FOLDER_COUNT " -lt 2 ]; then
199211 echo " FAIL: expected at least 2 Folder nodes (src, src/pkg), got $FOLDER_COUNT "
@@ -203,7 +215,7 @@ echo "OK: $FOLDER_COUNT Folder nodes (init.py didn't clobber them)"
203215
204216# 3d-cypher: query_graph Cypher capabilities
205217# #238 WITH DISTINCT — all functions share label "Function" → collapses to 1 row.
206- CYPHER_WD=$( cli query_graph " { \" project\" : \" $PROJECT \" , \" query\" : \" MATCH (f:Function) WITH DISTINCT f.label AS lbl RETURN lbl\" } " )
218+ CYPHER_WD=$( cli query_graph -- project " $PROJECT " -- query " MATCH (f:Function) WITH DISTINCT f.label AS lbl RETURN lbl" )
207219WD_ROWS=$( echo " $CYPHER_WD " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(len(d.get('rows',[])))" 2> /dev/null || echo " 0" )
208220if [ " $WD_ROWS " -lt 1 ]; then
209221 echo " FAIL: query_graph WITH DISTINCT returned 0 rows"
213225echo " OK: query_graph WITH DISTINCT returned $WD_ROWS row(s)"
214226
215227# #241 WHERE label test — f:Function is true for every Function node.
216- CYPHER_LBL=$( cli query_graph " { \" project\" : \" $PROJECT \" , \" query\" : \" MATCH (f:Function) WHERE f:Function RETURN f.name\" } " )
228+ CYPHER_LBL=$( cli query_graph -- project " $PROJECT " -- query " MATCH (f:Function) WHERE f:Function RETURN f.name" )
217229LBL_ROWS=$( echo " $CYPHER_LBL " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(len(d.get('rows',[])))" 2> /dev/null || echo " 0" )
218230if [ " $LBL_ROWS " -lt 1 ]; then
219231 echo " FAIL: query_graph WHERE label-test returned 0 rows"
223235echo " OK: query_graph WHERE f:Function returned $LBL_ROWS row(s)"
224236
225237# #242 label alternation — (n:Function|Module) seeds either label.
226- CYPHER_ALT=$( cli query_graph " { \" project\" : \" $PROJECT \" , \" query\" : \" MATCH (n:Function|Module) RETURN n.name\" } " )
238+ CYPHER_ALT=$( cli query_graph -- project " $PROJECT " -- query " MATCH (n:Function|Module) RETURN n.name" )
227239ALT_ROWS=$( echo " $CYPHER_ALT " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(len(d.get('rows',[])))" 2> /dev/null || echo " 0" )
228240if [ " $ALT_ROWS " -lt 1 ]; then
229241 echo " FAIL: query_graph label alternation returned 0 rows"
233245echo " OK: query_graph (n:Function|Module) returned $ALT_ROWS row(s)"
234246
235247# #239 count(DISTINCT) — must parse and return a single aggregate row.
236- CYPHER_CD=$( cli query_graph " { \" project\" : \" $PROJECT \" , \" query\" : \" MATCH (f:Function) RETURN count(DISTINCT f.label)\" } " )
248+ CYPHER_CD=$( cli query_graph -- project " $PROJECT " -- query " MATCH (f:Function) RETURN count(DISTINCT f.label)" )
237249CD_ROWS=$( echo " $CYPHER_CD " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(len(d.get('rows',[])))" 2> /dev/null || echo " 0" )
238250if [ " $CD_ROWS " -ne 1 ]; then
239251 echo " FAIL: query_graph count(DISTINCT) expected 1 row, got $CD_ROWS "
@@ -244,11 +256,10 @@ echo "OK: query_graph count(DISTINCT f.label) returned 1 aggregate row"
244256
245257# 3d-funcs: scalar / introspection functions (full Cypher suite, Tier 1)
246258cyp_first_cell () {
247- # $1 = query; echoes rows[0][0] (or empty)
248- # Escape embedded double-quotes so string-literal args (e.g. replace(x,"a","A"))
249- # don't break the JSON we build by interpolation.
250- local q=" ${1// \" / \\\" } "
251- cli query_graph " {\" project\" :\" $PROJECT \" ,\" query\" :\" $q \" }" |
259+ # $1 = query; echoes rows[0][0] (or empty). Flag form passes the query as ONE
260+ # argv token, so string-literal args (e.g. replace(f.name,"a","A")) and Cypher
261+ # metacharacters {}|=~<>" need no JSON escaping.
262+ cli query_graph --project " $PROJECT " --query " $1 " |
252263 python3 -c " import json,sys; d=json.loads(sys.stdin.read()); rows=d.get('rows',[]); print(rows[0][0] if rows and rows[0] else '')" 2> /dev/null || echo " "
253264}
254265
@@ -303,15 +314,15 @@ if [ -z "$COALV" ]; then echo "FAIL: query_graph coalesce(...) returned empty";
303314echo " OK: query_graph coalesce(f.nonesuch, f.name) = $COALV "
304315
305316# EXISTS { } pattern predicate (edge-type-specific existence)
306- CYPHER_EX=$( cli query_graph " { \" project\" : \" $PROJECT \" , \" query\" : \" MATCH (f:Function) WHERE EXISTS { (f)-[:CALLS]->() } RETURN f.name\" } " )
317+ CYPHER_EX=$( cli query_graph -- project " $PROJECT " -- query " MATCH (f:Function) WHERE EXISTS { (f)-[:CALLS]->() } RETURN f.name" )
307318EX_ROWS=$( echo " $CYPHER_EX " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(len(d.get('rows',[])))" 2> /dev/null || echo " 0" )
308319if [ " $EX_ROWS " -lt 1 ]; then
309320 echo " FAIL: query_graph EXISTS{} predicate returned 0 rows" ; echo " $CYPHER_EX " ; exit 1
310321fi
311322echo " OK: query_graph EXISTS { (f)-[:CALLS]->() } returned $EX_ROWS row(s)"
312323
313324# =~ regex match in WHERE
314- CYPHER_RX=$( cli query_graph " { \" project\" : \" $PROJECT \" , \" query\" : \" MATCH (f:Function) WHERE f.name =~ \\\ " .+\\\ " RETURN f.name\" } " )
325+ CYPHER_RX=$( cli query_graph -- project " $PROJECT " -- query ' MATCH (f:Function) WHERE f.name =~ ".+" RETURN f.name' )
315326RX_ROWS=$( echo " $CYPHER_RX " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(len(d.get('rows',[])))" 2> /dev/null || echo " 0" )
316327if [ " $RX_ROWS " -lt 1 ]; then
317328 echo " FAIL: query_graph WHERE =~ regex returned 0 rows" ; echo " $CYPHER_RX " ; exit 1
@@ -334,7 +345,7 @@ LEFTV=$(cyp_first_cell 'MATCH (f:Function) RETURN left(f.name, 3) AS l LIMIT 1')
334345[ -n " $LEFTV " ] && echo " OK: query_graph left(f.name,3) = $LEFTV " || { echo " FAIL: left empty" ; exit 1; }
335346
336347# NOT EXISTS dead-code query (functions with no caller)
337- CYPHER_NX=$( cli query_graph " { \" project\" : \" $PROJECT \" , \" query\" : \" MATCH (f:Function) WHERE NOT EXISTS { (f)<-[:CALLS]-() } RETURN f.name\" } " )
348+ CYPHER_NX=$( cli query_graph -- project " $PROJECT " -- query " MATCH (f:Function) WHERE NOT EXISTS { (f)<-[:CALLS]-() } RETURN f.name" )
338349NX_OK=$( echo " $CYPHER_NX " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print('rows' in d)" 2> /dev/null || echo " False" )
339350[ " $NX_OK " = " True" ] && echo " OK: query_graph NOT EXISTS dead-code query executed" || { echo " FAIL: NOT EXISTS query" ; echo " $CYPHER_NX " | head -c 300; exit 1; }
340351
@@ -345,7 +356,7 @@ CASEV=$(cyp_first_cell 'MATCH (f:Function) RETURN CASE WHEN f.name =~ ".+" THEN
345356# unsupported function must FAIL LOUDLY (not silently return empty). The CLI
346357# prints the parse error to stderr (captured by cli() into $CLI_STDERR) and exits
347358# non-zero, leaving stdout empty — so verify the loud failure on that channel.
348- if cli query_graph " { \" project\" : \" $PROJECT \" , \" query\" : \" MATCH (f:Function) RETURN nosuchfn(f.name)\" } " > /dev/null; then
359+ if cli query_graph -- project " $PROJECT " -- query " MATCH (f:Function) RETURN nosuchfn(f.name)" > /dev/null; then
349360 echo " FAIL: unsupported function did not error (exit 0)" ; exit 1
350361fi
351362ERROUT=$( cat " $CLI_STDERR " 2> /dev/null)
@@ -355,30 +366,137 @@ case "$ERROUT" in
355366esac
356367
357368# 3f: get_architecture surfaces Leiden community clusters
358- ARCH=$( cli get_architecture " {\" project\" :\" $PROJECT \" ,\" aspects\" :[\" clusters\" ]}" )
369+ if ! ARCH=$( cli get_architecture --project " $PROJECT " --aspects clusters) ; then
370+ echo " FAIL: get_architecture (flag form) exited non-zero" ; cat " $CLI_STDERR " ; exit 1
371+ fi
359372NCLUST=$( echo " $ARCH " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); print(len(d.get('clusters',[])))" 2> /dev/null || echo " 0" )
360373if [ " $NCLUST " -lt 1 ]; then
361374 echo " FAIL: get_architecture returned 0 community clusters" ; echo " $ARCH " | head -c 400; exit 1
362375fi
363376echo " OK: get_architecture returned $NCLUST community cluster(s)"
364377
365378# 3g: search_code — basic search reports elapsed_ms + matches
366- SC=$( cli search_code " { \" project\" : \" $PROJECT \" , \" pattern\" : \" cbm_\" , \" mode\" : \" compact\" , \" limit\" :5} " )
379+ SC=$( cli search_code -- project " $PROJECT " -- pattern cbm_ -- mode compact -- limit 5 )
367380echo " $SC " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); assert 'elapsed_ms' in d; print('OK: search_code elapsed_ms='+str(d['elapsed_ms'])+' total_grep_matches='+str(d.get('total_grep_matches')))" 2> /dev/null || { echo " FAIL: search_code basic / no elapsed_ms" ; echo " $SC " | head -c 400; exit 1; }
368381
369382# 3g: search_code — literal '|' under regex=false must surface a warning (#282)
370- SCW=$( cli search_code " { \" project\" : \" $PROJECT \" , \" pattern\" : \" cbm_init|cbm_nope\" , \" regex\" : false, \" limit\" :5} " )
383+ SCW=$( cli search_code -- project " $PROJECT " -- pattern " cbm_init|cbm_nope" -- regex false -- limit 5 )
371384echo " $SCW " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); w=' '.join(d.get('warnings',[])); assert 'regex=true' in w; print('OK: search_code literal-| warning surfaced')" 2> /dev/null || { echo " FAIL: search_code literal-| warning missing" ; echo " $SCW " | head -c 400; exit 1; }
372385
373386# 3g: search_code — '&' in file_pattern accepted, not rejected as invalid (#272)
374- SCA=$( cli search_code " { \" project\" : \" $PROJECT \" , \" pattern\" : \" cbm_\" , \" file_pattern \" : \" *R&D*.c\" , \" limit\" :5} " )
387+ SCA=$( cli search_code -- project " $PROJECT " -- pattern cbm_ --file-pattern " *R&D*.c" -- limit 5 )
375388case " $SCA " in
376389 * " invalid characters" * ) echo " FAIL: search_code rejected '&' in file_pattern" ; echo " $SCA " | head -c 300; exit 1 ;;
377390 * ) echo " OK: search_code accepts '&' in file_pattern" ;;
378391esac
379392
393+ echo " "
394+ echo " === Phase 3h: CLI input-mode guards (flags / stdin / --args-file / --help / deprecation) ==="
395+
396+ # Small helper: assert its stdin is a JSON object (exit non-zero otherwise).
397+ assert_json_obj () { python3 -c " import json,sys; d=json.loads(sys.stdin.read()); sys.exit(0 if isinstance(d,dict) else 1)" 2> /dev/null; }
398+
399+ # B1: INTEGER flag — --limit is schema-typed integer; must parse to valid JSON.
400+ if ! IM_INT=$( cli search_graph --project " $PROJECT " --name-pattern compute --limit 5) ; then
401+ echo " FAIL B1: search_graph --limit 5 exited non-zero" ; cat " $CLI_STDERR " ; exit 1
402+ fi
403+ if echo " $IM_INT " | assert_json_obj; then
404+ echo " OK B1: INTEGER flag (--limit 5) parsed → valid JSON"
405+ else
406+ echo " FAIL B1: --limit 5 did not produce valid JSON" ; echo " $IM_INT " | head -c 300; exit 1
407+ fi
408+
409+ # B2: BOOLEAN bare flag — --exclude-entry-points with no value → true; must succeed.
410+ if ! IM_BOOL=$( cli search_graph --project " $PROJECT " --exclude-entry-points) ; then
411+ echo " FAIL B2: search_graph --exclude-entry-points exited non-zero" ; cat " $CLI_STDERR " ; exit 1
412+ fi
413+ if echo " $IM_BOOL " | assert_json_obj; then
414+ echo " OK B2: BOOLEAN bare flag (--exclude-entry-points) → success"
415+ else
416+ echo " FAIL B2: --exclude-entry-points did not produce valid JSON" ; echo " $IM_BOOL " | head -c 300; exit 1
417+ fi
418+
419+ # B3: ARRAY flag — repeated --semantic-query accumulates into a JSON array.
420+ # semantic_results may be empty (index-mode dependent); only assert valid JSON.
421+ if ! IM_ARR=$( cli search_graph --project " $PROJECT " --semantic-query send --semantic-query publish) ; then
422+ echo " FAIL B3: search_graph repeated --semantic-query exited non-zero" ; cat " $CLI_STDERR " ; exit 1
423+ fi
424+ if echo " $IM_ARR " | assert_json_obj; then
425+ echo " OK B3: ARRAY flag (repeated --semantic-query) → valid JSON"
426+ else
427+ echo " FAIL B3: repeated --semantic-query did not produce valid JSON" ; echo " $IM_ARR " | head -c 300; exit 1
428+ fi
429+
430+ # B4: STDIN — piped JSON resolves; this path must NOT emit a deprecation warning.
431+ IM_STDIN=$( echo " {\" project\" :\" $PROJECT \" }" | " $BINARY " cli get_graph_schema 2> " $CLI_STDERR " )
432+ if ! echo " $IM_STDIN " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); sys.exit(0 if 'node_labels' in d else 1)" 2> /dev/null; then
433+ echo " FAIL B4: stdin get_graph_schema did not resolve" ; echo " $IM_STDIN " | head -c 300; cat " $CLI_STDERR " ; exit 1
434+ fi
435+ if grep -qi ' deprecated' " $CLI_STDERR " ; then
436+ echo " FAIL B4: stdin path wrongly emitted a deprecation warning" ; cat " $CLI_STDERR " ; exit 1
437+ fi
438+ echo " OK B4: STDIN input resolves, no deprecation warning"
439+
440+ # B5: --args-file — JSON read from a file resolves; must NOT warn deprecated.
441+ IM_ARGS_FILE=$( mktemp)
442+ echo " {\" project\" :\" $PROJECT \" }" > " $IM_ARGS_FILE "
443+ if ! IM_AF=$( cli get_graph_schema --args-file " $IM_ARGS_FILE " ) ; then
444+ echo " FAIL B5: get_graph_schema --args-file exited non-zero" ; cat " $CLI_STDERR " ; rm -f " $IM_ARGS_FILE " ; exit 1
445+ fi
446+ if ! echo " $IM_AF " | python3 -c " import json,sys; d=json.loads(sys.stdin.read()); sys.exit(0 if 'node_labels' in d else 1)" 2> /dev/null; then
447+ echo " FAIL B5: --args-file get_graph_schema did not resolve" ; echo " $IM_AF " | head -c 300; rm -f " $IM_ARGS_FILE " ; exit 1
448+ fi
449+ if grep -qi ' deprecated' " $CLI_STDERR " ; then
450+ echo " FAIL B5: --args-file path wrongly emitted a deprecation warning" ; cat " $CLI_STDERR " ; rm -f " $IM_ARGS_FILE " ; exit 1
451+ fi
452+ rm -f " $IM_ARGS_FILE "
453+ echo " OK B5: --args-file input resolves, no deprecation warning"
454+
455+ # B6: per-tool --help — RC0 with expected flags in stdout; unknown tool errors non-zero.
456+ if ! H_SG=$( cli search_graph --help) ; then
457+ echo " FAIL B6a: 'search_graph --help' exited non-zero" ; exit 1
458+ fi
459+ if echo " $H_SG " | grep -q -- " --name-pattern" ; then
460+ echo " OK B6a: search_graph --help (RC0) lists --name-pattern"
461+ else
462+ echo " FAIL B6a: search_graph --help missing --name-pattern" ; echo " $H_SG " | head -c 400; exit 1
463+ fi
464+ if ! H_IR=$( cli index_repository --help) ; then
465+ echo " FAIL B6b: 'index_repository --help' exited non-zero" ; exit 1
466+ fi
467+ if echo " $H_IR " | grep -q -- " --repo-path" ; then
468+ echo " OK B6b: index_repository --help (RC0) lists --repo-path"
469+ else
470+ echo " FAIL B6b: index_repository --help missing --repo-path" ; echo " $H_IR " | head -c 400; exit 1
471+ fi
472+ # Unknown tool: must exit non-zero and report "unknown tool" (on stderr).
473+ if cli notatool --help > /dev/null; then
474+ echo " FAIL B6c: 'notatool --help' exited 0 (expected non-zero for unknown tool)" ; exit 1
475+ fi
476+ if grep -qi ' unknown tool' " $CLI_STDERR " ; then
477+ echo " OK B6c: 'notatool --help' errors non-zero with 'unknown tool'"
478+ else
479+ echo " FAIL B6c: 'notatool --help' did not report 'unknown tool'" ; cat " $CLI_STDERR " ; exit 1
480+ fi
481+
482+ # B7: DEPRECATION guard — one raw-JSON call MUST warn on stderr; flag form must NOT.
483+ cli search_graph " {\" project\" :\" $PROJECT \" ,\" name_pattern\" :\" compute\" }" > /dev/null || true
484+ if grep -qi ' deprecated' " $CLI_STDERR " ; then
485+ echo " OK B7a: raw-JSON cli emits deprecation warning on stderr"
486+ else
487+ echo " FAIL B7a: raw-JSON cli did NOT emit deprecation warning" ; cat " $CLI_STDERR " ; exit 1
488+ fi
489+ cli search_graph --project " $PROJECT " --name-pattern compute > /dev/null || true
490+ if grep -qi ' deprecated' " $CLI_STDERR " ; then
491+ echo " FAIL B7b: flag-form cli wrongly emitted a deprecation warning" ; cat " $CLI_STDERR " ; exit 1
492+ else
493+ echo " OK B7b: flag-form cli emits no deprecation warning"
494+ fi
495+
380496# 3e: delete_project cleanup
381- cli delete_project " {\" project\" :\" $PROJECT \" }" > /dev/null
497+ if ! cli delete_project --project " $PROJECT " > /dev/null; then
498+ echo " FAIL: delete_project (flag form) exited non-zero" ; cat " $CLI_STDERR " ; exit 1
499+ fi
382500
383501echo " "
384502echo " === Phase 4: security checks ==="
0 commit comments