Skip to content

cli: add deny-list tests and a catalog.db existence check for infoctl query #93

Closed

Description

@codecapo

infoctl query has to stay read-only (#15). At a0b5e6c the command is still a stub (crates/cli/src/main.rs:18-21); PR #46 implements it by running each query through DataFusion's sql_with_options with SQLOptions that deny DDL, DML and statements such as SET, and tests that COPY, INSERT, CREATE TABLE AS, DROP and SET are rejected. Three more ways to write, or to read files outside the warehouse, are blocked in PR #46 but not tested: CREATE EXTERNAL TABLE ... LOCATION (blocked only by with_allow_ddl(false)), a file path used as a table name, as in SELECT * FROM '/path' (blocked only because the query session never calls enable_url_table), and EXPLAIN ANALYZE INSERT (blocked because the with_allow_dml(false) check also looks inside what EXPLAIN ANALYZE wraps), so a later change to the options or the session could reopen any of them without CI noticing. Separately, PR #46 checks only that the --warehouse directory exists, while Warehouse::open_local opens the SQLite catalog with mode=rwc and so creates catalog.db when it is missing (crates/storage/src/lib.rs:88-95): pointed at an existing directory that is not a warehouse, such as .infostash rather than the default .infostash/warehouse, the command writes an empty catalog there and then answers as if the warehouse had no tables. The file name is set by the private CATALOG_FILE constant (crates/storage/src/lib.rs:69). Repeat it in the CLI check, with a comment that points at that constant, rather than add public API to crates/storage; the existing CLI tests build their warehouses through Warehouse::open_local, so they will fail if the two names ever differ. Run the tests with cargo test -p infostash-engine --test query and cargo test -p infostash-cli --test query. If PR #46 is still open, its author may fold this work into it; otherwise, start from main after PR #46 has merged. The QueryContext parameter, loading every table's head together before registering any, the memory limit with an output cap, and the short infoctl query RFC are separate work in #95.

Crates: crates/engine (tests/query.rs, next to statements_that_write_are_rejected) and crates/cli (src/lib.rs and tests/query.rs), all in files that PR #46 adds

Done when

  • Test: CREATE EXTERNAL TABLE t STORED AS CSV LOCATION '<path>', where the path names a small CSV file the test writes into its temp directory, is rejected with an Error::Plan whose message contains not supported and CreateExternalTable.
  • Test: EXPLAIN ANALYZE INSERT INTO ready.daily_revenue VALUES ('2026-10-03', 5) is rejected with an Error::Plan whose message contains not supported, and the table's row count is unchanged afterwards.
  • Test: SELECT * FROM '<path>' on the same CSV file returns an error rather than the file's rows, so the test fails if the query session ever turns on enable_url_table; assert only that it fails, because with URL tables off the path is looked up as an ordinary table name and the error need not say not supported.
  • infoctl query checks that <warehouse>/catalog.db exists as a file before it calls Warehouse::open_local, next to the existing is_dir() check in crates/cli/src/lib.rs, and otherwise exits 1 with the same no warehouse at error that PR feat(cli): infoctl query runs read-only SQL against the warehouse #46 gives for a missing directory.
  • Test: infoctl query --warehouse <dir> "select 1" on an existing empty directory exits 1 with that error and leaves the directory empty, next to a_missing_warehouse_is_an_error_and_creates_nothing in crates/cli/tests/query.rs.

Points: 1 (M4 three deny-list tests and catalog.db existence check 1)

Depends on: #15 (the infoctl query command this extends)
Blocks: nothing

Source: design review of 2026-11-01, section 7.3 (points from section 8.5, M4).

Activity

  1. added this to the 0.1.0 milestone on Nov 6, 2026
  2. added a commit that references this issue on Nov 9, 2026
    b3017eb
  3. codecapo commented on Nov 10, 2026

    @codecapo
    OwnerAuthor

    Follow-up from the review of #46: infoctl query still opens the catalog with mode=rwc, so a zero-byte or non-SQLite catalog.db is created or has catalog tables written into it on the first open. Add to this ticket:

    • refuse a zero-byte or non-SQLite catalog file without changing it;
    • open SQLite with mode=ro on the query path, through a read-only variant of Warehouse::open_local or a flag, so no read-only command can create catalog tables;
    • a test for each.
  4. codecapo commented on Nov 10, 2026

    @codecapo
    OwnerAuthor

    The read-only catalog follow-up noted above moved to #104, since this ticket closed with #46.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions