Skip to content
Open
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
11 changes: 4 additions & 7 deletions packages/host/tests/integration/realm-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -988,11 +988,8 @@ module('Integration | realm', function (hooks) {
data: {
type: 'card',
attributes: {
email: null,
posts: null,
firstName: 'Van Gogh',
lastName: 'Abdel-Rahman',
cardInfo,
},
meta: {
adoptsFrom: {
Expand Down Expand Up @@ -1170,7 +1167,6 @@ module('Integration | realm', function (hooks) {
],
sponsors: ['Burton'],
posts: [],
cardInfo,
},
meta: {
adoptsFrom: {
Expand Down Expand Up @@ -1234,6 +1230,9 @@ module('Integration | realm', function (hooks) {
'pets.0': {
links: { self: `${testRealmURL}dir/van-gogh` },
},
'pets.1': {
links: { self: `${testRealmURL}dir/mango` },
},
friend: { links: { self: `${testRealmURL}dir/friend` } },
},
meta: {
Expand Down Expand Up @@ -1388,7 +1387,7 @@ module('Integration | realm', function (hooks) {
{
data: {
type: 'card',
attributes: { firstName: 'Jackie', cardInfo },
attributes: { firstName: 'Jackie' },
relationships: {
'pets.0': { links: { self: `./dir/van-gogh` } },
friend: { links: { self: `./dir/friend` } },
Expand Down Expand Up @@ -2331,7 +2330,6 @@ module('Integration | realm', function (hooks) {
type: 'card',
attributes: {
firstName: 'Mango',
cardInfo,
},
relationships: {
owner: {
Expand Down Expand Up @@ -2495,7 +2493,6 @@ module('Integration | realm', function (hooks) {
model: 'C300',
year: '2024',
},
cardInfo,
},
meta: {
adoptsFrom: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ module('Integration | tools | check-correctness', function (hooks) {
fileIdentifier: `${cardId}.json`,
codeBlocks: [
`╔═══ SEARCH ════╗
"name": "Bill",
"hasError": true,
"name": "Bill"
╠═══════════════╣
"name": "Billy",
"hasError": false,
"name": "Billy"
╚═══ REPLACE ═══╝`,
],
roomId,
Expand Down
128 changes: 128 additions & 0 deletions packages/realm-server/tests/atomic-endpoints-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,134 @@ module(basename(import.meta.filename), function () {
testRealmAdapter.write = originalWrite;
}
});

test('waitForIndex write preserves compound field values backed by an unexported FieldDef', async function (assert) {
let logSource = `
import {
contains,
containsMany,
field,
CardDef,
FieldDef,
} from "@cardstack/base/card-api";
import StringField from "@cardstack/base/string";
import DatetimeField from "@cardstack/base/datetime";

class Entry extends FieldDef {
@field kind = contains(StringField);
@field at = contains(DatetimeField);
@field headline = contains(StringField);
}

export class Log extends CardDef {
@field logTitle = contains(StringField);
@field entries = containsMany(Entry);
}
`.trim();
let moduleDoc = {
'atomic:operations': [
{
op: 'add',
href: 'log.gts',
data: {
type: 'source',
attributes: {
content: logSource,
},
meta: {},
},
},
],
};
await request
.post('/_atomic?waitForIndex=true')
.set('Accept', SupportedMimeType.JSONAPI)
.set(
'Authorization',
`Bearer ${createJWT(testRealm, 'user', ['read', 'write'])}`,
)
.send(JSON.stringify(moduleDoc))
.expect(201);

// Instance pushed as a raw `source` resource — the shape realm
// sync tools send — so the handler re-serializes it through
// fileSerialization before writing to disk.
let instanceContent = JSON.stringify(
{
data: {
type: 'card',
attributes: {
logTitle: 'Probe',
entries: [
{
kind: 'phase',
at: '2026-07-17T02:45:29.259Z',
headline: 'probe entry',
},
],
},
meta: {
adoptsFrom: {
module: '../log',
name: 'Log',
},
},
},
},
null,
2,
);
let instanceDoc = {
'atomic:operations': [
{
op: 'add',
href: 'Log/log-1.json',
data: {
type: 'source',
attributes: {
content: instanceContent,
},
meta: {},
},
},
],
};
let response = await request
.post('/_atomic?waitForIndex=true')
.set('Accept', SupportedMimeType.JSONAPI)
.set(
'Authorization',
`Bearer ${createJWT(testRealm, 'user', ['read', 'write'])}`,
)
.send(JSON.stringify(instanceDoc));
assert.strictEqual(
response.status,
201,
`expected 201, got ${response.status}: ${JSON.stringify(response.body)}`,
);

let sourceResponse = await request
.get('/Log/log-1.json')
.set('Accept', SupportedMimeType.CardSource);
assert.strictEqual(sourceResponse.status, 200);
let storedDoc = JSON.parse(sourceResponse.text);
assert.deepEqual(
storedDoc.data.attributes?.entries,
[
{
kind: 'phase',
at: '2026-07-17T02:45:29.259Z',
headline: 'probe entry',
},
],
'containsMany compound entries survive the waitForIndex write',
);
assert.strictEqual(
storedDoc.data.attributes?.logTitle,
'Probe',
'top-level attribute survives the waitForIndex write',
);
});
});
module('error handling', function (hooks) {
setupPermissionedRealmCached(hooks, {
Expand Down
Loading
Loading