Skip to content

Commit 849d5dc

Browse files
add GC prompt
1 parent b12bf99 commit 849d5dc

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

prompt-tombstonesGCScenarios.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Porting Ably LiveObjects JavaScript integration tests to Swift
2+
3+
## Overview
4+
5+
Take a look at the attached Repomix output. This belongs to a codebase called ably-js, which offers the same LiveObjects functionality as this Swift plugin. The file objects.test.js offers various integration tests for the LiveObjects functionality. I wish to port these tests to Swift.
6+
7+
I have already:
8+
9+
- ported the ObjectsHelper class
10+
- chosen how to map the JavaScript tests' parameterised testing to Swift Testing
11+
- ported the objectSyncScenarios, applyOperationsScenarios, writeAPIScenarios, and subscriptionCallbacksScenarios (with the aid of an LLM)
12+
13+
You can see all of this in @ObjectsIntegrationTests.swift.
14+
15+
Your task is to port the tombstonesGCScenarios to Swift. Begin by creating a TODO list for the remaining tests, then work on this TODO list.
16+
17+
## Requirements specific to these ported tests
18+
19+
Here is guidance on how to port the private API usage in the JS tests. We provide test hooks equivalent to those in JS. You will need to begin by casting the public types to their internal proxy types (e.g. port the `any RealtimeObjects` to `PublicDefaultRealtimeObjects` etc) in order to access these testing APIs (then need to go via the `proxied` property to get to underlying `InternalDefaultRealtimeObjects` etc).
20+
21+
- `helper.recordPrivateApi('call.Objects._objectsPool.get')`: use `InternalDefaultRealtimeObjects.testsOnly_objectsPool`
22+
- `helper.recordPrivateApi('call.LiveObject.isTombstoned')`: use `InternalDefaultLiveCounter.isTombstone` (ditto for LiveMap)
23+
- `helper.recordPrivateApi('read.LiveMap._dataRef.data')`: use `InternalDefaultLiveMap.testsOnly_data`
24+
- `helper.recordPrivateApi('write.Objects._DEFAULTS.gcInterval')` and `helper.recordPrivateApi('write.Objects._DEFAULTS.gcGracePeriod')`: use `PartialClientOptions.garbageCollectionOptions` when creating the `ARTRealtime` instance. Note that the JS values are in milliseconds.
25+
- `helper.recordPrivateApi('replace.Objects._objectsPool._onGCInterval')`: the JS tests override this in order to find out that LiveObjects garbage collection has occurred. You can instead use `InternalDefaultRealtimeObjects.testsOnly_completedGarbageCollectionEvents`, which emits an element each time garbage collection occcurs.
26+
27+
## Detailed general requirements for the ported tests
28+
29+
Take the following requirements into account when coming up with your plan.
30+
31+
- When translating the JS code to Swift, follow the existing patterns established by the already-ported tests where possible.
32+
33+
Also consider the following requirements, which I supplied to the LLM when it ported the objectSyncScenarios. Some of these requirements are likely already represented in the tests that have been ported so far.
34+
35+
- Do not omit any actions or assertions from the JavaScript implementation except when explicitly instructed to do so. If you are not able to convert part of the JavaScript implementation, leave a TODO comment explaining what needs to be done.
36+
- If the JavaScript tests assume that an object is non-null but this is not something that the Swift compiler inherently knows, favour using Swift Testing's #require macro instead of force unwrapping.
37+
- Handle JavaScript calls to the expectInstanceOf function as follows:
38+
- If it is a check that we don't need because it's guaranteed by the Swift type system, then don't copy this call; instead just add a comment in its place explaining why it's been omitted.
39+
- If it is a check that a LiveMap contains an entry of a particular type, then keep the check but instead of checking the type of the value, check that it has the correct case in the LiveMapValue enum (you can use the liveCounterValue etc convenience getters for this).
40+
- When converting a simple inline assertion about the contents of a LiveMap, convert by following this example: `expect(valuesMap.get('stringKey')).to.equal('stringValue', 'Check values map has correct string value key')` should become `#expect(try #require(valuesMap.get(key: "stringKey")?.stringValue) == "stringValue", "Check values map has correct string value key")`.
41+
- In one place, the JavaScript tests call channel.client; this property does not exist in the Swift equivalent so instead create a local variable called let client = context.client at the top of the method and use this.
42+
- When the JavaScript tests use a local variable that is a `Promise` which will be awaited later (usually the naming will indicate this; e.g. `counterCreatedPromise`), represent this in Swift as an `async let` variable of the same name, e.g. `async let counterCreatedPromise`.
43+
- When the JavaScript tests use a local variable that is a fixed-size array of `Promise`s that will be awaited later, then use an `async let` local array variable of the same name.
44+
- When the JavaScript tests use a local variable that is a variable-size array of `Promise`s that will be awaited later, then use an `async let` variable that is backed by a `TaskGroup.`
45+
- Our ObjectsHelper doesn't take a helper argument.
46+
- We converted ably-js's `channel.attach()` into a call to our internal helper `channel.attachAsync()` which uses Swift Concurrency; we may need these for other methods too. You can add these helper methods in the Ably+Concurrency.swift file.
47+
- We have no helper instance that's passed to each test; the methods that exist on `helper` are currently just static methods on `Helper`.
48+
- do not copy the calls to `helper.recordPrivateAPI`; they're not relevant in this codebase
49+
- when the calls to `helper.recordPrivateAPI` refer to a piece of functionality that is easy to implement as a test helper, do so (e.g. Base64 decoding, or comparison of binary data)
50+
- when the calls to `helper.recordPrivateAPI` refer to a piece of functionality that seem to genuinely require the LiveObjects SDK to provide a special test hook, add a stub helper method for doing this which calls `fatalError()`, with a TODO in it
51+
- If you need to add any of the top-level helper functions from the JavaScript file, then add them as top-level functions in the Swift test file
52+
- The aim is to get the tests to compile; they are not yet expected to pass and you do not need to run the tests

0 commit comments

Comments
 (0)