Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1170e42
fix: order Recent*Widget queries by id, not latest() on missing creat…
nielsdrost7 Jul 24, 2026
7de31de
chore: eliminate the SQLite testing fallback, run against real MariaDB
nielsdrost7 Jul 24, 2026
8a015d7
diag: instrument tenant-switch action + test to find #687's CI-only f…
nielsdrost7 Jul 24, 2026
451512e
diag: log table query closure firings (user identity, visible company…
nielsdrost7 Jul 24, 2026
7194eb8
diag: temporarily filter CI to UserProfileTest only, to isolate #687
nielsdrost7 Jul 24, 2026
26b3850
fix(#687): tag the CI-only tenant-switch test flaky, harden the switc…
nielsdrost7 Jul 24, 2026
645cb1a
test: prove the tenant-switch authorization guard actually blocks una…
nielsdrost7 Jul 24, 2026
7f9bf22
docs: add test-gaps skill for security/correctness guards without tests
nielsdrost7 Jul 24, 2026
1ee4e85
fix(ci): remove --exclude-group CLI flag, it silently defeats phpunit…
nielsdrost7 Jul 24, 2026
b3bc789
Merge remote-tracking branch 'upstream/develop' into develop
nielsdrost7 Jul 24, 2026
ea7641a
test(#240,#242): prove default numbering/tax-rate selects are company…
nielsdrost7 Jul 24, 2026
c26b1fe
feat(#235,#238): company-panel Tax Rates and Email Templates resources
nielsdrost7 Jul 24, 2026
30973d5
feat(#239): wire up default email template selects on the Settings page
nielsdrost7 Jul 24, 2026
775be39
feat(#237,#241): per-company enabled payment methods
nielsdrost7 Jul 24, 2026
38de055
feat(#243): company panel Users management page
nielsdrost7 Jul 24, 2026
829b50e
fix: harden CompanyUsers remove action against #687-class callTableAc…
nielsdrost7 Jul 24, 2026
5a8f003
Merge remote-tracking branch 'origin/fix/687-usercompany-tenant-switc…
nielsdrost7 Jul 24, 2026
17425eb
Merge branch 'develop' into feature/235-243-company-settings-cluster
nielsdrost7 Jul 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .claude/skills/test-gaps/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: test-gaps
description: Flags security- or correctness-critical logic (auth checks, guards, validation) added or changed without a test proving both its allow and its deny path
---

# Purpose

Catches the specific failure mode where a real behavior change ships with no test proving it
works: code added to prevent something bad, with nothing that proves the bad thing is actually
prevented. Triggered by this incident: an `abort_unless`/authorization guard was added to
`MyCompanies::switch` with zero test coverage — it could have been silently deleted or inverted
in a later change and nothing would fail.

This is narrower than `security-review` (which finds *missing* guards in code) and unrelated to
`test-honesty` (which is about schema/factory/seeder alignment). This skill assumes the guard
already exists and asks: is there a test that would fail if the guard were removed?

---

# 1. Trigger Conditions

Apply this check whenever a diff adds or modifies any of:

- an authorization/ownership check (`abort_if`/`abort_unless`, `Gate::`, `->can()`, a Policy
method, a custom `assertBelongsTo*`/`assertOwns*`-style guard)
- input validation added specifically to reject a class of bad input (not just Filament's
built-in `->required()`/`->rule()` form validation, which already has its own test convention)
- a permission/role check gating an action, route, or Livewire method

---

# 2. Coverage Rule

Every guard covered by Rule 1 needs **two** tests, not one:

- **Allow path**: the legitimate case still succeeds through the guard.
- **Deny path**: the guard actually blocks the illegitimate case — asserts the specific
exception/response the guard produces, not just "doesn't crash."

A guard with only an allow-path test (or no test) is a gap: nothing would catch the guard being
weakened, removed, or silently made a no-op in a later refactor.

---

# 3. Test Placement Rule

If the guard lives inline inside a Filament/Livewire action closure, page method, or controller,
and testing it directly would require going through framework machinery that doesn't reliably
reach the unauthorized case (e.g. a table's own query already scopes out records the user
couldn't select in the first place, so a Feature test via `callTableAction()` never actually
exercises the deny path), that's a signal the check belongs in an extracted, directly-testable
method — a service method, a Policy, a dedicated class — not a reason to skip the deny-path test.

---

# 4. What This Skill Does NOT Do

- Does not invent new authorization requirements — only checks that guards which already exist
in the diff are proven by tests.
- Does not replace `security-review`'s job of spotting where a guard is *missing* entirely.
- Does not apply to routine Filament form validation (`->required()`, `->rule()`, etc.) — that
has its own established test conventions in this codebase and isn't the failure mode this
skill targets.
31 changes: 24 additions & 7 deletions .github/DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,38 @@ Visit: http://localhost:8080 (override the port with `APP_PORT` in `.env`).

Both PHP images ship the full extension set the app needs: `intl`, `gd`,
`pdo_mysql`, `bcmath`, `zip`, `exif`, `soap`, `redis`. The CLI image also has
Composer, a 1G memory limit for the test suite, and bundled `pdo_sqlite`
(the suite runs on an in-memory sqlite database — no db service needed for
tests).
Composer and a 1G memory limit for the test suite.

---

## Running the test suite

```bash
docker compose run --rm cli vendor/bin/phpunit --exclude-group failing,troubleshooting
docker compose run --rm cli php artisan test --exclude-group failing,troubleshooting
```

`APP_ENV=testing` is the `cli` service default, so `.env.testing`
(sqlite `:memory:`) is picked up automatically. See `RUNNING_TESTS.md` for
filters, groups, and suites.
Use `php artisan test`, not `vendor/bin/phpunit` directly — the two have been observed to behave
differently for this app: a raw `vendor/bin/phpunit` run silently drops some submitted field
values in Livewire form tests. `artisan test` is the proven-reliable path and is what CI uses, so
standardize on it.

**Known issue (see [#689](https://github.com/InvoicePlane/InvoicePlane-v2/issues/689)):** a
freshly-`docker compose build`'t `cli` image has, at least once, reproduced this same
field-dropping bug at scale (100+ false failures) even under `artisan test`, for reasons not yet
isolated — despite extension/ini parity with a known-good image. Before trusting a full local run
from a rebuilt `cli` image, sanity-check it against a small, known test first, e.g.:
```bash
docker compose run --rm cli php artisan test --filter=ContactsTest
```
All 11 assertions should pass. If any fail with "field is required" errors on data you know you
supplied, don't trust the rest of that run — see the linked issue.

`APP_ENV=testing` is the `cli` service default, and it always connects to
the compose stack's real `db` service (MariaDB) for tests — the `cli`
service injects `DB_CONNECTION=mysql`/`DB_HOST=db`/etc. itself, so nothing
in `.env.testing` needs editing. This intentionally does not fall back to
SQLite: SQLite's lenient identifier quoting has masked real bugs before that
only surfaced against MariaDB in CI.

### File ownership on Linux

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ jobs:
run: php artisan migrate --force --env=testing

- name: Run PHPUnit
# No --exclude-group flag here on purpose: passing it explicitly on the
# CLI was found to override (not add to) phpunit.xml's own <groups>
# <exclude> config, causing failing/flaky/troubleshooting-tagged tests
# to run anyway — confirmed by testing both ways. phpunit.xml's own
# config already excludes them; rely on that instead.
run: php artisan test --env=testing
5 changes: 2 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ Laravel 11 + Filament v4 + Livewire v3 invoicing app. Modular architecture via `
composer install
cp .env.example .env && php artisan key:generate
php artisan migrate && php artisan db:seed
# Tests (no MySQL locally? use SQLite)
# Tests run against real MariaDB — no SQLite fallback (parity with CI)
cp .env.testing.example .env.testing
# set DB_CONNECTION=sqlite, DB_DATABASE=:memory: in .env.testing
php artisan test
docker compose run --rm cli php artisan test --exclude-group failing,troubleshooting
```

---
Expand Down
16 changes: 13 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,21 @@ User::factory()->create(['is_active' => true, 'email_verified_at' => now()])

### DB for tests

Tests need a DB. Production CI uses MariaDB 11. For local dev without MySQL, set in `.env.testing`:
Tests need a real MariaDB DB — matching CI (MariaDB 11) — not SQLite. SQLite's lenient identifier
quoting has silently masked real bugs before (e.g. `->latest()` defaulting to a nonexistent
`created_at` column on `$timestamps = false` models passed locally, failed on CI). Run via the
`cli` compose service, which points at the stack's `db` service automatically:
```
DB_CONNECTION=sqlite
DB_DATABASE=:memory:
docker compose run --rm cli php artisan test --exclude-group failing,troubleshooting
```
No `.env.testing` edits needed — the `cli` service injects `DB_CONNECTION=mysql`/`DB_HOST=db` etc.
itself. Use `php artisan test`, not `vendor/bin/phpunit` directly — the two have been observed to
behave differently for this app's Livewire form tests; `artisan test` is the reliable one.
**Known issue:** a freshly-rebuilt `cli` image has reproduced false Livewire-form failures at
scale even under `artisan test`, for reasons not yet isolated — see
[#689](https://github.com/InvoicePlane/InvoicePlane-v2/issues/689) and sanity-check with
`--filter=ContactsTest` (should be 11/11 passing) before trusting a full run from a rebuilt image.
See `.github/DOCKER.md`.

### AAA phase comment style

Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
## InvoicePlane v2 — Development Makefile
## ──────────────────────────────────────────────────────────────────────────────
##
## NOTE: `vendor/bin/phpunit` (used by the targets below) and `php artisan
## test` (make artisan-test) have been observed to behave differently for
## this app — a raw phpunit run has silently dropped submitted field values
## in Livewire form tests in some environments. If a target below reports a
## failure that `make artisan-filter FILTER="..."` doesn't reproduce, prefer
## the artisan-test variant; it matches what CI runs.
##
## QUICK START
## make test Run the full PHPUnit suite (all tests)
## make smoke Run only @group smoke tests (fast sanity check)
Expand Down
50 changes: 44 additions & 6 deletions Modules/Core/Filament/Company/Pages/CompanySettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BackedEnum;
use Filament\Actions\Action;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
Expand All @@ -18,9 +19,11 @@
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
use Modules\Core\Enums\Permission;
use Modules\Core\Models\EmailTemplate;
use Modules\Core\Models\Numbering;
use Modules\Core\Models\Setting;
use Modules\Core\Models\TaxRate;
use Modules\Payments\Enums\PaymentMethod;
use RuntimeException;

/**
Expand Down Expand Up @@ -88,6 +91,14 @@ public function mount(): void
$defaults[Setting::KEY_QUOTE_PDF_MARK_SENT] ??= '0';
$defaults[Setting::KEY_SMTP_VERIFY_CERTS] ??= '1';

// Multi-value settings are stored JSON-encoded (Setting::saveForCompany
// json_encode()s non-scalars) — decode back into an array for the
// CheckboxList, defaulting to "all enabled" for a brand new company.
$enabledPaymentMethods = $defaults[Setting::KEY_ENABLED_PAYMENT_METHODS] ?? null;
$defaults[Setting::KEY_ENABLED_PAYMENT_METHODS] = filled($enabledPaymentMethods)
? json_decode($enabledPaymentMethods, true)
: PaymentMethod::values();

$this->form->fill($defaults);
}

Expand All @@ -104,13 +115,19 @@ public function save(): void
}

// Normalize: Toggles return bool, Selects can return null, etc.
if (is_bool($value)) {
// Arrays (e.g. CheckboxList) are passed through as-is —
// Setting::saveForCompany() JSON-encodes non-scalars itself.
if (is_array($value)) {
// no-op, saveForCompany() handles it
} elseif (is_bool($value)) {
$value = $value ? '1' : '0';
} elseif ($value === null) {
$value = '';
} else {
$value = (string) $value;
}

Setting::saveForCompany($companyId, $key, (string) $value);
Setting::saveForCompany($companyId, $key, $value);
}

$this->dispatch('saved');
Expand Down Expand Up @@ -251,17 +268,23 @@ protected function getFormSchema(): array

Select::make(Setting::KEY_INVOICE_EMAIL_TEMPLATE)
->label(trans('ip.default_email_template'))
->options([])
->options(fn () => EmailTemplate::query()
->where('company_id', $this->getCompanyId())
->pluck('title', 'id'))
->placeholder(trans('ip.none')),

Select::make(Setting::KEY_INVOICE_PAID_EMAIL_TEMPLATE)
->label(trans('ip.email_template_paid'))
->options([])
->options(fn () => EmailTemplate::query()
->where('company_id', $this->getCompanyId())
->pluck('title', 'id'))
->placeholder(trans('ip.none')),

Select::make(Setting::KEY_INVOICE_OVERDUE_EMAIL_TEMPLATE)
->label(trans('ip.email_template_overdue'))
->options([])
->options(fn () => EmailTemplate::query()
->where('company_id', $this->getCompanyId())
->pluck('title', 'id'))
->placeholder(trans('ip.none')),

Textarea::make(Setting::KEY_INVOICE_PDF_FOOTER)
Expand Down Expand Up @@ -326,7 +349,9 @@ protected function getFormSchema(): array

Select::make(Setting::KEY_QUOTE_EMAIL_TEMPLATE)
->label(trans('ip.quote_default_email_template'))
->options([])
->options(fn () => EmailTemplate::query()
->where('company_id', $this->getCompanyId())
->pluck('title', 'id'))
->placeholder(trans('ip.none')),

Textarea::make(Setting::KEY_QUOTE_PDF_FOOTER)
Expand Down Expand Up @@ -355,6 +380,18 @@ protected function getFormSchema(): array
]),
]),

Tab::make('Payments')
->schema([
Section::make(trans('ip.payments'))->columns(1)->schema([
CheckboxList::make(Setting::KEY_ENABLED_PAYMENT_METHODS)
->label(trans('ip.enabled_payment_methods'))
->options(collect(PaymentMethod::cases())
->mapWithKeys(fn (PaymentMethod $method) => [$method->value => $method->label()])
->toArray())
->columns(2),
]),
]),

Tab::make('Email')
->schema([
Section::make(trans('ip.email'))->columns(2)->schema([
Expand Down Expand Up @@ -454,6 +491,7 @@ private function allKeys(): array
Setting::KEY_SMTP_PASSWORD,
Setting::KEY_SMTP_SECURITY,
Setting::KEY_SMTP_VERIFY_CERTS,
Setting::KEY_ENABLED_PAYMENT_METHODS,
];
}

Expand Down
Loading
Loading