Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"area": "mdl/executor", "date": "2026-11-17", "refs": ["ako/mxcli#1258"], "ce": ["CE0002"], "symptom": "`create association M.A_A from M.A to M.A owner both` (and child->parent, parent->child, a longer chain, Reference and ReferenceSet alike) passed `mxcli check` and `exec`; `mx check` then reported CE0002. An unrelated pair with owner both, and every other owner, built with 0 errors.", "file": "mdl/executor/validate_association_owner_both.go ValidateAssociationOwnerBoth (MDL099), called from validate_program.go. Tests: validate_association_owner_both_test.go; fixtures mdl-examples/bug-tests/association-owner-both-self(.fail).mdl", "cause": "Nothing compared an association's two ends when owner is Both. A comment in validate_retrieve_association_list.go already said 'Owner Both on a self-reference is CE0002' as a reason a case could not arise, so the fact was known in the codebase but never enforced as a rule.", "insight": "**A code comment that cites a CE number as the reason a case 'cannot arise' is a pointer to an unenforced rule: grep the source for `CE0` in comments before measuring a gap list from scratch.** Boundary measured on MxBuild 11.16.1, 7 shapes in separate project copies: self, child->parent, parent->child, grandchild chain and ReferenceSet versions are CE0002; owner default and an unrelated pair are clean. Only generalizations the script declares are followed (an entity extending one in the project still reaches mx check), so it refuses less, not more. Sweep: 1,312 repo .mdl files, 0 MDL099 hits. Control: stubbing the rule fails the table test; the control fixture builds with 0 errors."}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"area": "mdl/executor", "date": "2026-11-17", "refs": ["ako/mxcli#2374"], "ce": [], "symptom": "TestSnapshotDependents_FindsAssociationsWithoutABaseline (cmd/mxcli/marketplace) failed intermittently: `dependents = []; want MyFirstModule.Config_Account`. Red in CI on main at cd4076243 and on an unrelated PR twice, green at 208a4e6e6; 1 failure in 5 local runs on main. Any read that follows a write within the same second as the previous catalog build answered from the catalog as it was before the write.", "file": "mdl/catalog/catalog.go ModTimeUnchanged (new) and SetCacheInfo/GetCacheInfo (RFC3339Nano); callers mdl/executor/cmd_catalog.go catalogCurrent and isCacheValid, cmd/mxcli/cmd_describe.go catalogMatchesProject. Tests: mdl/catalog/catalog_test.go, mdl/executor/catalog_freshness_subsecond_test.go, cmd/mxcli/catalog_matches_project_subsecond_test.go, cmd/mxcli/marketplace/snapshot_same_second_test.go", "cause": "Three freshness checks compared the project file's mtime as whole Unix seconds, and the cache stored it with time.RFC3339 (whole seconds). A write in the same second as the build left the cache looking fresh. The comment justifying it ('handle timezone/precision issues') was about a real worry, but Unix() is already zone independent and an exact Equal on the stored instant has neither problem.", "insight": "**An intermittent failure whose rate is a fraction of a second over a timing window is a cache key that is too coarse: look for a whole-second timestamp compare before blaming the test or the runner.** Settled by a scratch test that Chtimes the project to a fixed instant, then moves the write +500ms (same second: stale, dependents=0) versus +1500ms (control: seen, dependents=1) - deterministic, where the original test was red 1 run in 6. Three sites compared seconds, not one; grep `.Unix() !=` near MprModTime found all of them. Caches written before the fix hold whole seconds and never equal a fractional mtime, so each project rebuilds once; no wrong answer. Control: reverting ModTimeUnchanged to a seconds compare fails the same-second subtests (marketplace, executor, describe) while the one-second-later control still passes."}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Fixed

- **`check` rejects `owner both` between an entity and itself or its generalization** (ako/mxcli#1258) — `create association M.A_A from M.A to M.A owner both`, or from a specialization to its parent (either direction, any chain, Reference or ReferenceSet), passed `check` and `exec` and the build reported CE0002. New MDL099, which needs no project; an unrelated pair and every other owner are unaffected. Only generalizations the script declares are followed. Measured on MxBuild 11.16.1.
- **The catalog cache sees a write made in the same second as the build** (ako/mxcli#2374) — freshness compared the project file's modification time as whole seconds, so a read that followed a write inside the second of the previous catalog build answered from the catalog as it was before the write (`marketplace update` finding no dependent associations about one run in six; `describe` and catalog queries could do the same). The time is now stored and compared to the nanosecond. A cache written by an older mxcli holds whole seconds and is rebuilt once per project.
- **`alter page … set (visible: roles (…))` sets the module roles** (ako/mxcli#2371) — the alter form stored `roles (…)` as the visibility expression, reported success, and left a page `mx check` rejected with CE0117. It now writes the "Visible for module roles" setting as `create page` does, keeping the widget's condition, and `roles (…) and <condition>` sets both.
- **`check` reports a `limit 1` list returned as a single object** (ako/mxcli#2364) — under `mdl 1;` `retrieve … limit 1` binds a list of one, and returning it from a microflow that returns the entity passed check and exec, then failed `mx check` with CE0117 at the End event. MDL-RETRIEVE03 now reports it and suggests `first`, `head($Item)` or a list return type.
- **`sql --describe schema.table` describes the table** (ako/mxcli#2361) — the qualified name `--tables` suggests returned an empty column list and no error on PostgreSQL and SQL Server. It now matches schema and table, a table that is not found is an error naming the accepted form, and an unqualified name held by several schemas is refused with the candidates instead of listing all their columns as one table.
Expand Down
51 changes: 51 additions & 0 deletions cmd/mxcli/catalog_matches_project_subsecond_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: Apache-2.0

package main

import (
"os"
"path/filepath"
"testing"
"time"

"github.com/mendixlabs/mxcli/mdl/catalog"
)

// catalogMatchesProject decides whether `describe` may answer from the cache
// instead of scanning the project. It compared whole seconds, so a project
// modified within the second of the build still matched.
func TestCatalogMatchesProject_WriteInTheSameSecondAsTheBuild(t *testing.T) {
mpr := filepath.Join(t.TempDir(), "app.mpr")
if err := os.WriteFile(mpr, []byte("x"), 0o644); err != nil {
t.Fatal(err)
}
fi, err := os.Stat(mpr)
if err != nil {
t.Fatal(err)
}
cat, err := catalog.New()
if err != nil {
t.Fatal(err)
}
defer cat.Close()
if err := cat.SetCacheInfo(catalog.AbsMprPath(mpr), fi.ModTime(), "11.8.0", "fast", time.Second); err != nil {
t.Fatal(err)
}
if !catalogMatchesProject(cat, mpr) {
t.Fatal("control: an unchanged project must match its cache")
}

moved := fi.ModTime().Add(300 * time.Millisecond)
if fi.ModTime().Nanosecond() > 500_000_000 {
moved = fi.ModTime().Add(-300 * time.Millisecond)
}
if err := os.Chtimes(mpr, moved, moved); err != nil {
t.Fatal(err)
}
if got, _ := os.Stat(mpr); got.ModTime().Unix() != fi.ModTime().Unix() || got.ModTime().Equal(fi.ModTime()) {
t.Fatalf("setup: %v -> %v is not a change inside one second", fi.ModTime(), got.ModTime())
}
if catalogMatchesProject(cat, mpr) {
t.Error("a project modified inside the second of the build still matched its cache")
}
}
4 changes: 2 additions & 2 deletions cmd/mxcli/cmd_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func resolveViaCatalog(projectPath, name string) []string {

// catalogMatchesProject reports whether the cached catalog was built from the
// current project file and is still up to date — same MPR path and unchanged
// modification time (Unix seconds, mirroring isCacheValid). Any read failure or
// modification time (the same instant, mirroring isCacheValid). Any read failure or
// mismatch is treated as "not fresh" so the caller live-scans (safe but slower).
func catalogMatchesProject(cat *catalog.Catalog, projectPath string) bool {
info, err := cat.GetCacheInfo()
Expand All @@ -529,7 +529,7 @@ func catalogMatchesProject(cat *catalog.Catalog, projectPath string) bool {
if err != nil {
return false
}
if info.MprModTime.Unix() != fi.ModTime().Unix() {
if !catalog.ModTimeUnchanged(info.MprModTime, fi.ModTime()) {
return false
}
// Compare absolute paths when both resolve; a path mismatch means the cache
Expand Down
51 changes: 51 additions & 0 deletions cmd/mxcli/marketplace/snapshot_same_second_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: Apache-2.0

package marketplace

import (
"os"
"testing"
"time"
)

// TestSnapshotDependents_SeesAWriteInTheSecondOfTheFirstRead is the deterministic
// form of what TestSnapshotDependents_FindsAssociationsWithoutABaseline did by
// chance: the first read builds the catalog, the write follows it, and when both
// land in one second the second read must still see the write. The catalog cache
// compared whole seconds, so it answered from the build made before the write
// and returned no dependents (about one run in six; red on main at cd4076243).
//
// The control is the same sequence with the write a second later, which was
// always seen.
func TestSnapshotDependents_SeesAWriteInTheSecondOfTheFirstRead(t *testing.T) {
for _, tc := range []struct {
name string
after time.Duration
}{
{"write in the same second", 500 * time.Millisecond},
{"write a second later (control)", 1500 * time.Millisecond},
} {
t.Run(tc.name, func(t *testing.T) {
target := copyFixture(t)
at := time.Now().Truncate(time.Second)
if err := os.Chtimes(target, at, at); err != nil {
t.Fatal(err)
}
if _, err := SnapshotDependents(target, "Administration", testBackend); err != nil {
t.Fatal(err)
}
execMDL(t, target, crossModuleAssocMDL)
written := at.Add(tc.after)
if err := os.Chtimes(target, written, written); err != nil {
t.Fatal(err)
}
deps, err := SnapshotDependents(target, "Administration", testBackend)
if err != nil {
t.Fatal(err)
}
if len(deps) != 1 || deps[0].Key.Name != crossModuleAssoc {
t.Fatalf("dependents = %+v; want %s", deps, crossModuleAssoc)
}
})
}
}
Loading
Loading