Skip to content

feat(ost): add .ost, a file format for idempotent test scripts - #667

Merged
christianeu-db merged 27 commits into
apache:mainfrom
julianhyde:501-ost
Nov 12, 2026
Merged

christianeu-db merged 27 commits into
apache:mainfrom
julianhyde:501-ost

Conversation

@julianhyde

Copy link
Copy Markdown
Contributor

Summary

Add OST (Ossie SQL Test, file suffix.ost), a file format for idempotent test scripts.

Each test script contains the expected output of each command, and "idempotent" means that if the test script succeeds it generates itself. If a test script fails, it generates a script that would succeed if it were copied over the original. (The user must of course check that the output is correct.)

Example:

# File header with copyright
# 
# An example .ost (Ossie SQL Test) file.

# Connect to a particular database.
connect("postgres");

# A test case that is a SQL query.
# Because there is no ORDER BY clause, any output order is acceptable.
# Changes in whitespace are also acceptable.
select *
from emps
where job = 'CLERK';
+-------+--------+-----------+------+------------+---------+---------+--------+
| EMPNO | ENAME  | JOB       | MGR  | HIREDATE   | SAL     | COMM    | DEPTNO |
+-------+--------+-----------+------+------------+---------+---------+--------+
|  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 |         |     10 |
|  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800.00 |         |     20 |
|  7876 | ADAMS  | CLERK     | 7788 | 1987-05-23 | 1100.00 |         |     20 |
|  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950.00 |         |     30 |
+-------+--------+-----------+------+------------+---------+---------+--------+
(4 rows)

# End example.ost

Related Issues

Fixes #501

Checklist

Specification

  • Spec changes are included in core-spec/ and follow the existing structure
  • Spec changes have been discussed on the mailing list or in a linked issue
  • Breaking changes to the spec are clearly called out in the summary

Ontology

  • Ontology changes in ontology/ are consistent with spec changes
  • New or modified terms are defined and documented

Converters

Validation

  • Validation rules in validation/ are updated if the spec changed
  • New validation cases are covered by tests

Documentation

  • docs/ is updated to reflect any user-facing changes
  • New features or behaviors are documented with examples where appropriate
  • CONTRIBUTING.md is updated if the contribution process changed

Examples

  • examples/ are added or updated for any new spec constructs

Tests

  • All existing tests pass (pytest / CI green)
  • New functionality is covered by tests

Compliance

  • ASF license headers are present on all new source files
  • No third-party dependencies are added without PMC/IPMC approval
  • If third-party source code is vendored/copied (not just declared as a dependency), NOTICE and/or LICENSE have been updated per ASF policy

Specify the .ost (Ossie SQL Test) script format and the ost command
that runs it: commands and how they end, output forms (tables,
values, raw strings, errors), formatting of each type in the common
core of DuckDB and Postgres, lenient matching and regeneration, the
built-in functions, and a Python API for running a script held in a
string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thank you for your first contribution to Apache Ossie (incubating)!

A committer will review your PR. In the meantime, please ensure:

  • All CI checks pass
  • ASF license headers are present on new source files
  • Tests cover new functionality

No ICLA is required to contribute. If you are elected as a committer in the future, you will need an Individual Contributor License Agreement (ICLA) on file with the ASF.

Questions? Ask in the PR comments or join us on Slack.

We appreciate your contribution!

@github-actions github-actions Bot added the infra label Oct 31, 2026
@julianhyde julianhyde changed the title Add .ost, a file format for idempotent test scripts feat(ost): add .ost, a file format for idempotent test scripts Oct 31, 2026
julianhyde and others added 12 commits October 31, 2026 00:29
Add the ost uv project, with a lexical parser that splits a script
into verbatim chunks and commands with their expected output, such
that writing the chunks back gives the script byte for byte.

The parser rejects tabs, carriage returns and trailing spaces; finds
the ';' that ends each command, skipping parentheses, quoted strings,
comments and raw strings; and recognizes output blocks (tables,
values, raw strings and errors). It also splits function calls and
parses their arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a runner that executes each command of a script against an
in-memory DuckDB database, compares its output with the expected
output, and writes the regenerated script. It formats values of the
common core types, matches leniently (rows in any order unless the
query is ordered, padding and border widths ignored), and implements
the built-in functions connect, query, queryOrdered, queryUnordered,
plus, set and ost.

Add the ost command, with --update, --output-dir, --echo and
--timeout. For each script that fails, it prints the paths of the
script and of the regenerated script, and a diff between them.

Add the SCOTT fixture, the run() Python API, and tests, including
the example script from the specification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move tests that check a script's output into the scripts
matching.ost, types.ost and functions.ost, which test_script runs.
Keep in Python the tests that check failures, the timeout, custom
functions, malformed scripts, and raw_string.

Add tests that rows match in any order and despite differences in
whitespace, and that when a script fails, a command whose output
matched keeps its expected row order.

Add the ASF license header to each script, which Apache RAT
requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a workflow that, when files under ost/ change, runs pytest and
the .ost scripts on Python 3.11 to 3.14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Show how to write a script with one query, run it, copy the
regenerated script over it, and run it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parser split a script into lines with str.splitlines, which also
breaks at characters such as form feed, U+0085 and U+2028, but it
counted the lines of a command by '\n', so a command containing one
of those characters was cut short. Split lines only at '\n', in the
parser, when reading a table, and when computing a diff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pache#501)

json.dumps escapes only the C0 control characters, so ost wrote DEL,
the C1 control characters, U+2028 and U+2029 verbatim inside quoted
strings, where they are hard to see and an editor may treat them as
line breaks. Write them as \uXXXX, and say so in the specification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
To scan each command, the parser joined the lines from the command
to the end of the script, so parsing took time quadratic in the
length of the script; a script of 64,000 commands took two minutes.
Scan each command in the text of the whole script instead, and find
the line on which it ends by binary search. That script now takes
under a second.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a table does not match, ost puts the actual rows in the order of
the expected rows. It looked up and removed each expected row in a
list of the actual rows, which took time quadratic in the number of
rows; a table of 80,000 rows took over a minute. Count the rows
instead. That table now takes under a second.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a command's timeout expired, ost interrupted DuckDB once. DuckDB
ignores an interrupt that arrives between statements, so a command of
many fast statements could run far past its timeout and still
succeed. Interrupt repeatedly until the command finishes, and report
a timeout whenever it expired. A lock ensures that no interrupt
arrives after the command finishes, where it could affect the next
one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tinct (apache#501)

ost wrote the regenerated script for a script outside the current
directory at its file name, so `ost /a/x/test.ost /b/y/test.ost`
wrote both to `target/ost/test.ost`, and the second overwrote the
first. Add `-d dir` (default `.`): a regenerated script is written
under `dir/target/ost` at the script's path relative to `dir`, so
`ost a/b/c.ost` in a directory and `ost -d .. b/c.ost` in its
subdirectory `a` write the same file. A script outside `dir` is
written under `ost/target` in the temporary directory, at its
absolute path. A relative `--output-dir` is now relative to `dir`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For each script that failed, ost printed
`ost: a.ost failed; regenerated script is target/ost/a.ost`.
Instead, print `ost: there were failures` once, before the first
failing script, then for each failing script a command such as
`diff -u a.ost target/ost/a.ost`, followed by its output. Paths in
the command are quoted for the shell, so it can be pasted as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread ost/docs/ost.md Outdated
* A value, if a function returns a value.
* An error, if the command fails.

If the lines after a command contain more than one table, value or

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the queries that generate the expanded SQL, can there be be multiple valid outputs? Can that be expressed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a given query and model, the reference implementation would produce just one SQL expansion. In that sense, this test is just testing the reference implementation of the view expander.

By many measures, the reference implementation isn't that great: it only generates one dialect of SQL, is not very fast (written in Python), and the SQL that is generated may not be efficient (I envision lots of correlated subqueries).

But in another sense, this test is testing any compliant implementation. Because a compliant implementation may generate different SQL, but it needs to generate SQL that gives the same results.

Comment thread ost/docs/ost.md

* Nothing. A command that produces nothing (such as `connect`, or a
`create table` statement) has no output.
* A table, if the command returns rows.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe order or rows in the table is not important, would there be a way to optionally enforce order?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, queryOrdered. There's an example in types.ost.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker: an ordered query does not need a unique sort key, so the order of tied rows (order by deptno over emp) is up to the engine. Could we add the compliance rule "the sort key MUST order the result uniquely"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that ORDER BY is not always deterministic. I'm not sure that a compliance rule would help much... I prefer to say that developers should write deterministic tests.

There are other subtle cases like queries that return 0 or 1 rows and therefore have deterministic ordering, and use of ORDER BY inside window aggregates. "Write deterministic tests" covers it all.

Comment thread ost/docs/ost.md

Each script starts as if it began with `connect("empty")`.

`query(sql)`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the earlier example shows a sql query without the query function. Would the files have query(sql) or would they have sql directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc for query(sql) says

Executes sql; equivalent to writing sql as a SQL command.

Comment thread ost/docs/ost.md
: Closes the current database, and opens a new in-memory DuckDB
database, loaded with the fixture *name*. Fixtures are:
* `"empty"` - no tables.
* `"scott"` - the SCOTT schema: tables `dept`, `emp`, `bonus` and

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the script contain the sql statements that create necessary tables and fill in data, or would that be out of band?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. DDL is not very portable between DBMSs and is slow. Best practice for writing tests would be to use built-in data sets.

# An example .ost (Ossie SQL Test) file.

# Connect to the SCOTT schema.
connect("scott");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the SQL inside the .ost file is syntax highlighted in PR description, what makes it do that? How can we do that for these files, in the common editors?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GitHub markdown, I use a sql code block. The highlighting looks reasonable because .ost is very similar to SQL.

Whatever editor you use - emacs, vim, VSCode, IntelliJ - I'm sure there's a way to associate the .ost file suffix with SQL code, but you're on your own.

Comment thread ost/docs/ost.md
shows only the rows that changed.

## FUNCTIONS

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the function to validate expanded SQL?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't one. Do we need one? When you execute an Ossie expression/query, ost will be expanding to SQL then executing the expanded SQL; during execution, the expanded SQL gets validated.

@christianeu-db christianeu-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really excited to see this materialize! Left a few minor comments (particularly interested in how we handle floating-point comparisons), but I think this is ready to move out of draft.

Given we're preparing for the initial release, I'd also like @jbonofre to spot-check the dependencies.

Comment thread ost/pyproject.toml
Comment on lines +22 to +42
[dependency-groups]
dev = [
"pytest>=8.0",
]

[project]
name = "apache-ossie-ost"
version = "0.2.0.dev0"
description = "Runner for Ossie SQL Test (.ost) scripts"
authors = [{ name = "Apache Software Foundation", email = "dev@ossie.apache.org" }]
requires-python = ">=3.11"
readme = "README.md"
license = "Apache-2.0"
keywords = [
"Apache Ossie",
"Ossie",
]
dependencies = [
"duckdb>=2.0.0",
"pytz>=2026.6",
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @jbonofre to verify if these are ok if we should get a thread rolling?

"TIMESTAMP": "timestamp",
"TIMESTAMP_S": "timestamp",
"TIMESTAMP_MS": "timestamp",
"TIMESTAMP_NS": "timestamp",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this drop nano-seconds in practice? my understanding was that postgres doesn't support nanosecond anyway so maybe makes sense to drop so this falls to unsupported type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind if the types are rather narrow. Every vendor's range is different, so we'll go crazy if we try to handle the full range. I want enough data types to be able to write "ordinary" queries to illustrate the query patterns. Types and built-in functions/operators are not what's under test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. The suggestion was more about if we just drop nano so it's treated as an error case for these tests

Comment thread ost/docs/ost.md Outdated
Matching is lenient. Row order, column widths and padding may differ
from the expected output, and the output still matches; when it
matches, the regenerated script keeps the expected output exactly as
it was written. When in doubt, `ost` reports a mismatch: a false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This says a false match would hide a bug, but a type change is a false match today. Expected output for select 1 as c matches select cast(1 as varchar) as c, and ost exits 0. Could we either document that types are not compared, or keep a type check?

FWIW, #632 had a lenient type check

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in the previous comment, types are not the main thing under test. The query

select *
from (values ('100', '21', '3')) as t (x)
order by x

would give the wrong result if the VARCHAR values are wrongly treated as INTEGER. But if I execute

select avg(sal)
from emp

I don't care very much whether avg(sal) is a REAL, DOUBLE or DECIMAL(7, 2).

For cases where the type matters, we could have a type function, e.g.

type(
  select deptno, avg(sal) as x
  from emp
  group by deptno);
> "{deptno: INTEGER, x: REAL} bag" : string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good - I'm happy to not to add that complexity

Comment thread ost/docs/ost.md Outdated
Comment on lines +340 to +342
The output of a script depends only on the script and the version
of the database; never on the time zone, locale or environment of
the machine that runs it. A script must therefore not use functions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A script can depend on the machine: read_text('/etc/hostname') runs, and COPY … TO '/tmp/x.csv' writes outside the output directory. Could connect run set enable_external_access = false after it loads the fixture?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed in 7ca909b.

Comment thread ost/docs/ost.md

* Nothing. A command that produces nothing (such as `connect`, or a
`create table` statement) has no output.
* A table, if the command returns rows.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker: an ordered query does not need a unique sort key, so the order of tied rows (order by deptno over emp) is up to the engine. Could we add the compliance rule "the sort key MUST order the result uniquely"?

Comment thread ost/src/ossie_ost/cli.py Outdated
from ossie_ost.parser import ScriptError, split_lines
from ossie_ost.runner import run

OUTSIDE_DIR = Path(tempfile.gettempdir()) / "ost/target"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a shared machine, other users can write to /tmp/ost/target. run_file creates the directories with mkdir(exist_ok=True) and writes with write_bytes (lines 138–139). It reuses directories that another user created, and it writes through symlinks. If that user plants a symlink at /tmp/ost/target/<your script's path>, ost overwrites the file the symlink points to. I reproduced this with a simulated temp directory. Could the fallback be a per-user directory instead, for example under ~/.cache, or tempfile.mkdtemp() printed in the diff command?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b9a0208. I made it use tempfile.mkdtemp() (typically /tmp/ost-XXXX). I chose not to use ~/.cache because that would not be reentrant for the current user, nor cleaned out on reboot.

Comment thread ost/docs/ost.md Outdated
* Two values are equivalent if their types are the same and their
values are the same. Spaces around ` : ` are ignored. A raw string
is equivalent to the quoted string with the same content.
* Two errors are equivalent if their messages are the same.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An expected error is the database's exact message, for example Catalog Error: Table with name nonexistent does not exist!. That pins DuckDB's wording, which no other engine produces and which can change between DuckDB versions. That's fine for the reference runner.

For cases that other implementations run, could we match something portable instead? Options include just > error for "this command fails", or an error class such as a SQLSTATE. Errors that ost raises itself (ost: unsupported type …) are deterministic and can stay exact.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that database error messages are not portable. Can you think of a case where we want to check database errors? If a table does not exist that's a fatal error (i.e. mistake by the author of the test, or an error beyond the system's control, like running out of memory).

I'm inclined to disallow DB failures entirely. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Layer 2, let's not test DB failures

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b0d5e41.

Comment thread ost/docs/ost.md Outdated
case, and their rows are the same. Cells are compared after
removing their padding, and after removing quotes and escapes from
quoted cells; the comparison is exact, so `x y` does not match
`x y`, and `800.00` does not match `800.0`. Border lines may

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current compliance suite is somewhat permissive with floating-point results, allowing a small relative difference. How have you handled this in the past?

I've seen other golden test suites use approximate matching, but another option would be to require queries to explicitly cast or format results for deterministic comparison.

That seems reasonable for Layer 2, where we control the SQL, but I'm less sure it translates cleanly to Layer 3, where the SQL is generated by the engine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in my other comments, I don't think the precise type or the precise value matter very much. If we are within 2 decimal places, we almost certainly generated the right query. The query author should craft queries so that wrong translations will give wrong results.

…pache#501)

A script could read or write any file that the user can, for example
`select * from read_text('/etc/passwd')`, and attach databases or
install extensions. Allow a script to access files only under the
`-d` directory (default: the current directory), by setting DuckDB's
`allowed_directories` and disabling `enable_external_access`; once
it is disabled, a script cannot enable it or change the allowed
directories. A relative path is also looked up in the script's
directory, so that a script can read a file beside it.

The Python API's `run` has new arguments `root` and `script_dir`. A
script run by the `ost` function has the same root and directory as
the script that runs it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@christianeu-db

Copy link
Copy Markdown
Contributor

@julianhyde looks good. I'm happy to merge once:

  1. The CI issue for 3.11 is addressed
  2. We get confirmation on the new dependneices

@jbonofre
jbonofre self-requested a review November 6, 2026 07:12
@jbonofre

jbonofre commented Nov 6, 2026

Copy link
Copy Markdown
Member

I'm starting the review on this one.

An f-string in test_file_access_root_and_script_dir used double
quotes inside a replacement field, which Python allows only from
3.12. The project requires 3.11 or later, and CI runs 3.11, where the
test module failed to parse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@julianhyde
julianhyde marked this pull request as ready for review November 6, 2026 21:29
Copilot AI balanced review requested due to automatic review settings November 6, 2026 21:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical validation bugs can falsely pass strict row-order mismatches and discard RETURNING rows, while escaped-string parsing and boundary REAL formatting also remain broken.

4 open issues
What changed in this PR

Introduces OST (.ost), a self-contained SQL test format for Ossie, with a Python harness that compares embedded expectations and regenerates scripts, implementing the approach proposed in #501.

Changes:

  • Adds parsing, DuckDB execution, output formatting and matching, plus extensible functions.
  • Provides an ost CLI with diffs, updates, timeouts, and restricted file access.
  • Adds format documentation, examples, automated tests, packaging, and CI.
File Description
ost/​uv.lock Locks runtime and test dependencies.
ost/​tests/​test_runner.py Tests execution, matching, formatting, and safeguards.
ost/​tests/​test_parser.py Tests parsing, whitespace, arguments, and round trips.
ost/​tests/​test_cli.py Tests CLI output, updates, paths, and errors.
ost/​tests/​scripts/​types.ost Exercises SQL value formatting.
ost/​tests/​scripts/​matching.ost Exercises ordering and lenient matching.
ost/​tests/​scripts/​functions.ost Exercises built-in functions and nested scripts.
ost/​tests/​scripts/​example.ost Demonstrates a complete OST script.
ost/​tests/​conftest.py Adds a license-only test configuration placeholder.
ost/​src/​ossie_ost/​runner.py Implements execution, rendering, matching, and regeneration.
ost/​src/​ossie_ost/​parser.py Parses commands and embedded expected output.
ost/​src/​ossie_ost/​fixtures/​scott.sql Supplies the SCOTT sample database.
ost/​src/​ossie_ost/​cli.py Implements script discovery, execution, diffs, and updates.
ost/​src/​ossie_ost/​__init__.py Exposes the Python API.
ost/​README.md Explains usage, development, and custom functions.
ost/​pyproject.toml Defines packaging, dependencies, and the CLI entry point.
ost/​docs/​ost.md Specifies the format, matching rules, CLI, and API.
.github/​workflows/​ost-ci.yml Runs tests and scripts across Python versions.

Review effort: Balanced

Comment on lines +661 to +664
if statement.type not in ROW_STATEMENTS and not (
statement.type in DML_STATEMENTS and columns != ("Count",)
):
return None
Comment thread ost/src/ossie_ost/runner.py Outdated
Comment on lines +716 to +717
if isinstance(actual, Table):
actual = reorder(actual, command)
Comment on lines +282 to +283
elif c in "'\"":
i = self._skip(i, c, i + 1, c)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bug that should be fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. The spec has the same conflict: the Commands table says that within " ... ", "" is a quote (SQL identifier rules), while Arguments says a string uses the escapes of JSON (RFC 8259).
The scanner follows the first rule, so an argument with an odd number of \" breaks.
For example, connect("a\"b"); is reported as unterminated command (open '"' at 1:14) instead of > error: ost: unknown fixture "a\"b". With an even number it works by accident. The test at test/test_parser.py:354 calls parse_args directly, so it never goes through the scanner.

The scanner runs before we know whether a command is a function call, so I see two options:

  1. Treat \ as escaping the next character inside " ... " everywhere. This is simple, but it changes how a SQL identifier containing \" is scanned, which should be rare.
  2. Keep the scanner as it is, and say in the spec that a " inside a quoted argument must be written \u0022 (or use a raw string).

I would go with 1 😄

Either way, the two sections of the spec should agree (I will create a PR about that), and a test at the script level (e.g. in functions.ost) would cover it.

Comment thread ost/src/ossie_ost/runner.py Resolved
khush-bhatia
khush-bhatia previously approved these changes Nov 7, 2026

@khush-bhatia khush-bhatia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good , thanks. Although the copilot reviews identified some bugs that should be fixed.

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @julianhyde it's really nice!

I found two issues worth to fix before merging (see inline):

  1. A JSON escaped \" in a string argument breaks command scanning (I commented in the existing thread).
  2. An --output-dir that points at the script own directory overwrites failing scripts and makes directory runs pass silently.

I have a few smaller findings (header escaping, $$ strings, the timeout not covering ost(), Python specific json error text in errors meant to be portable, and a couple of spec typos), it can come as follow-ups.

Comment thread ost/src/ossie_ost/cli.py Resolved

@kayemkim kayemkim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things from running this on macOS, next to the compliance/query suite it will absorb. Neither overlaps the scanner and --output-dir issues JB found.

test_file_access_denied[attach '/tmp/ost.db'] fails here on all four Python versions: /tmp is a symlink to /private/tmp, and DuckDB reports the resolved path for ATTACH (Cannot access file "/private/tmp/ost.db"), while the other five cases echo the path as written. Building the expected message from os.path.realpath('/tmp/ost.db'), or asserting on the Permission Error: Cannot access file prefix and the ost.db tail, would make it pass on both systems; GitHub's ubuntu runners never see the symlink, so CI stays green either way.

The scott fixture here differs from compliance/query/scott/scott.sql in types rather than values: TINYINT and SMALLINT keys, VARCHAR(n), no NOT NULL, salgrade in DECIMAL(7, 2), and bonus kept. The 32 cases should give the same rows when #502 converts them, since none selects losal or hisal, but a query that does would print 700.00 from this fixture and 700 from the other. Which copy is the one to keep after the conversion?

Handle OverflowError when converting string to float.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
julianhyde and others added 6 commits November 7, 2026 22:10
…pache#501)

In a string argument, "" is a quote and a backslash has no special
meaning, as in a PostgreSQL quoted identifier. Previously, string
arguments used the escapes of JSON while the scanner used SQL's rule,
so connect("a\"b"); was reported as an unterminated command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pache#501)

Before running a script, ost checks whether its output file is the
same file as the script. It compares the files' identities, not their
paths, so it detects symbolic links, hard links and case-insensitive
file systems; for example, "ost --output-dir . a.ost" previously
overwrote a.ost if it failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a summary (apache#501)

For each script, prints its path and whether it passed, failed, or
was malformed, after any failure output for it; at the end, prints a
summary such as "ost: 3 scripts, 2 passed, 1 failed". For "-", whose
standard output is the regenerated script, these lines go to
standard error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…able (apache#501)

When an unordered table did not match, ost reordered its rows to
follow the expected output, so that the diff would show only the rows
that changed. With matchStrict, which compares the output character
for character, that made the regenerated script identical to the
original, so a table whose rows were in a different order passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pache#501)

For ATTACH, DuckDB reports the path with symbolic links resolved. On
macOS, /tmp is a link to /private/tmp, so test_file_access_denied
failed there; build the expected message with os.path.realpath.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@julianhyde julianhyde left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbonofre @khush-bhatia @christianeu-db I've fixed all issues. Could I get a final +1? I need approval for the duckdb added dependency.

christianeu-db
christianeu-db previously approved these changes Nov 9, 2026

@christianeu-db christianeu-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM to merge. For getting the PPMC signoff for dependencies, you've gotten Khushboo and JB on this review so far. Perhaps @jklahr could be the third

One issue that can be a followup (would bias to merging this to unblock testing overall):

6de9ba3 fixes the single-file case, but a directory under the output directory still passes silently: ost --output-dir . cases/ runs 0 scripts and exits 0. Could that be a usage error (exit 2), or could running 0 scripts count as a failure?

…pache#501)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@julianhyde

Copy link
Copy Markdown
Contributor Author

@christianeu-db wrote:

6de9ba3 fixes the single-file case, but a directory under the output directory still passes silently: ost --output-dir . cases/ runs 0 scripts and exits 0. Could that be a usage error (exit 2), or could running 0 scripts count as a failure?

It's already mandatory to have at least one file argument. I just changed the synopsis to osc file... to reflect this. The problem is if that file is a directory, and that directory is empty.

I don't think that's a usage error, nor I don't think it's a runtime error. Simplest thing is to just allow it. I added --verbose mode so that, if you're mystified, you can see which tests ran, and how many succeeded and failed.

@christianeu-db

Copy link
Copy Markdown
Contributor

@julianhyde I started this thread: https://lists.apache.org/thread.html/r8stk3zp8dl2dxpdxp33j564h6wro3y5 to get the duckdb stuff unblocked

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great one @julianhyde! Thanks!

Also, +1 for duckdb and pytz (MIT) dependencies.

LGTM!

@ashlearnnext-star

Copy link
Copy Markdown
Contributor

@julianhyde can you please guide me, how we would like to merge these test cases into the OST format
#702

@christianeu-db
christianeu-db merged commit 3ca2097 into apache:main Nov 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add .ost, a file format for idempotent test scripts

8 participants