# Testing locally without releasing

You never need an installer or a release to try a change. There are two loops: the check script on the Linux host (fast, throwaway databases), and `Sage.exe` in the VM pointed straight at your working copies.

## Loop 1: the check script (Linux host)

Runs on the local PostgreSQL as a superuser, creates throwaway `check_<pid>_<n>` databases from `lesage/makedb/empty.sql` plus a synthetic seed, and drops them at the end. No client data involved.

```bash
cd ~/dev/improvize/common
export PGHOST=/var/run/postgresql   # over the socket: the TCP default asks for a password

npm run check -- lint sql ../lesage/sql     # no database: shape, forbidden SQL, released.json rules (seconds)
npm run check -- apply sql ../lesage/sql    # the apply cases below, common + lesage
npm run check -- all                        # lint + apply on common, lesage, inpro, aida and LS+IN
```

<table id="bkmrk-apply-caseproves-boo"><thead><tr><th>Apply case</th><th>Proves</th></tr></thead><tbody><tr><td>`bootstrap`</td><td>The whole bundle applies on an empty legacy database; a second run is `upToDate`; `functions.list` matches what was created; owners are right.</td></tr><tr><td>`replay`</td><td>A reinstall (every step again, on seeded tables) leaves the exact same schema: your steps are idempotent.</td></tr><tr><td>`reload`</td><td>The dev reload (functions + post) works and changes no schema.</td></tr><tr><td>`upgrade`</td><td>The last **released** version, then yours as a normal upgrade, gives the same schema as a fresh bootstrap: your new steps work on a database that already had version N.</td></tr><tr><td>`foreign`</td><td>Step 0001 refuses a database that isn't a Le Sage one (SQLSTATE `IZ001`).</td></tr></tbody></table>

Useful options: `--keep` keeps the throwaway databases so you can open them in psql; `--write-lists` rewrites `functions.list` after adding or removing a function.

## Loop 2: Sage.exe in the VM on `sage13test`

Two command-line parameters make the exe read your working copies:

- `sqlroot=Z:\dev\improvize\` — the exe reads `Z:\dev\improvize\common\sql\` and `Z:\dev\improvize\lesage\sql\` (the host's git checkouts through the VirtualBox share) instead of its own folder.
- `dev=1` — shows the reload buttons (main window and décomptes screen).

IDE run parameters (`Sage.params` already has the `SQLROOT` macro):

```
srv=192.168.56.1 user=jc pwd=0 owner=izowner db=sage13test sqlroot=Z:\dev\improvize\ dev=1
```

`sage13test` is the test copy of `sage12demo` owned by `izowner` (NOLOGIN), with `izowner_ddl` created by `ddl-roles.sql` and `jc` as a plain member login. That is the real hosted setup.

<p class="callout warning">Don't use the *"Local : sage12demo (bundles, dev)"* entry for this: its owner `cat` is a superuser, and the connect rule refuses to upgrade for a superuser owner (`ownersuperuser`). And never point a test exe at a client database.</p>

### What happens when you relaunch

<table id="bkmrk-you-didnext-launch-d"><thead><tr><th>You did</th><th>Next launch does</th></tr></thead><tbody><tr><td>Bumped `version` to 2 and added `0002-*.sql`</td><td>*upgrade* 1 → 2: runs the 0002 steps, then data, functions, post.</td></tr><tr><td>Edited anything again, version still 2</td><td>Checksum differs → *reinstall*: replays **every** step, then the rest. That's also a free idempotency test.</td></tr><tr><td>Nothing</td><td>*upToDate*, nothing written.</td></tr></tbody></table>

So the loop is simply: **edit the SQL on the host → relaunch Sage.exe**. No copy, no installer.

### Iterating on a function without relaunching

With `dev=1`, the reload button calls `ReloadBundles`: it reruns `functions/` and `post/` of both bundles (no steps, no cleanup, no version check) and marks the ledger `dirty`, so the next launch does a full reinstall. Good for tuning `calculatecopyright` or a décompte function in a running session.

### Useful SQL on the test database

```sql
-- where is it?
SELECT bundle, version, dirty, appliedat, appliedby FROM improvize.bundles;
SELECT * FROM improvize.bundlehistory ORDER BY id DESC LIMIT 10;

-- force a full replay at the next launch
UPDATE improvize.bundles SET dirty = true WHERE bundle = 'lesage';

-- you tested an unreleased version 2 and want to go back to an exe that ships 1
-- (otherwise: clientBehind). Next launch with 2 will upgrade 1 → 2 again.
UPDATE improvize.bundles SET version = 1, dirty = true WHERE bundle = 'lesage';
```

(As `cat`, superuser, on your local server. The ledger belongs to `izowner_ddl`.)

## Notes

- `~/dev/improvize/bundles-dev/` is an old manual copy from 4 Nov 2026, made when `lesage/sql` wasn't on `main` yet. Not needed any more: point `sqlroot` at `Z:\dev\improvize\`. Since 18 Nov 2026 it is the GitLab repo `improvize/bundles-dev`, without `common/` (that bundle is in `db-bundles`); nothing reads it.
- Le Sage web doesn't apply bundles yet (the web runner is still to come). Its `npm run build` runs `check lint` on both bundles in `prebuild`, so a bundle that fails lint breaks the web build too.
- A test database that received your unreleased version keeps working after the release: same checksum → *upToDate*; different checksum → *reinstall*.