Skip to content

Commit 9dd0862

Browse files
Prompts, Repomix, TODO.md for porting integration tests
These were used to generate the contents of #57. Try and turn some of this into some useful process in #60. Most of the prompt- files were based on top of each other, i.e. small modifications to the previous one, there might be a useful template here.
1 parent c5a5736 commit 9dd0862

16 files changed

Lines changed: 7305 additions & 0 deletions
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 (with the aid of an LLM)
12+
13+
You can see all of this in the attached ObjectsIntegrationTests.swift.
14+
15+
Ultrathink and create a step-by-step plan for how to use an LLM to port the remaining tests to Swift.
16+
17+
## Detailed requirements for the ported tests
18+
19+
Take the following requirements into account when coming up with your plan.
20+
21+
- When translating the JS code to Swift, follow the existing patterns established by objectSyncSequenceScenarios where possible.
22+
23+
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.
24+
25+
- 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.
26+
- 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.
27+
- Handle JavaScript calls to the expectInstanceOf function as follows:
28+
- 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.
29+
- 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).
30+
- 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")`.
31+
- 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.
32+
- 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`.
33+
- 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.
34+
- 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.`
35+
- Our ObjectsHelper doesn't take a helper argument.
36+
- 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.
37+
- We have no helper instance that's passed to each test; the methods that exist on `helper` are currently just static methods on `Helper`.
38+
- do not copy the calls to `helper.recordPrivateAPI`; they're not relevant in this codebase
39+
- 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)
40+
- 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
41+
- 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
42+
- 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

TODO.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- [ ] it has missed out some of the primitiveKeyData (e.g. max integer)
2+
- [x] the primitiveKeyData need DRYing up — and I need to understand what types they should be
3+
- [ ] some of the code that checks unsubscribe might be a bit racy — e.g. it might just be that you didn't see an update yet because you dispatched its handling into a `Task`
4+
- [ ] there are a bunch of `if case` statements in the tests which make me worry that some tests might end up being no-ops
5+
- [x] processDeserializedProtocolMessage should really be using the internal queue
6+
- [ ] bring in line with latest tests
7+
- [ ] make it know that when injecting a sequence of object operation messages, it matters that it be done sequentially else some operations will be skipped due to serial being less than last applied
8+
- [ ] why are the integration tests either failing (fatalError due to an assertion without a test being in progress, or just hanging) when logging is enabled?
9+
- [ ] consistently use one tool for handling synchronous subscriptions in integration tests (`Subscriber`? because that supports unsubscribe too) and then use that everywhere, and document it

prompt-DRY-up-fixtures.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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, subscriptionCallbacksScenarios, and applyOperationsDuringSyncScenarios (with the aid of an LLM)
12+
13+
You can see all of this in @ObjectsIntegrationTests.swift.
14+
15+
The LLM that ported the tests did not do a good job of porting the fixtures. Instead of porting the top level fixtures, it has created individual local variable fixtures in each of the tests. I wish for you to rectify this mistake and DRY up these fixtures. I want you to create top level variables for primitiveKeyData, primitiveMapsFixtures, and countersFixtures, and update the tests to use these.
16+
17+
In the case where the local variable in a test currently has some additional fields, such as the swiftValue or the restData, I want you to include this value in the top level fixtures, such that the top level data is the union of all the fields in the current local variables. And I want there to be a comment explaining exactly why this additional field exists.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 applyOperationsDuringSyncScenarios to Swift. Begin by creating a TODO list for the remaining tests, then work on this TODO list.
16+
17+
## Detailed general requirements for the ported tests
18+
19+
Take the following requirements into account when coming up with your plan.
20+
21+
- When translating the JS code to Swift, follow the existing patterns established by the already-ported tests where possible.
22+
23+
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.
24+
25+
- 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.
26+
- 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.
27+
- Handle JavaScript calls to the expectInstanceOf function as follows:
28+
- 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.
29+
- 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).
30+
- 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")`.
31+
- 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.
32+
- 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`.
33+
- 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.
34+
- 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.`
35+
- Our ObjectsHelper doesn't take a helper argument.
36+
- 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.
37+
- We have no helper instance that's passed to each test; the methods that exist on `helper` are currently just static methods on `Helper`.
38+
- do not copy the calls to `helper.recordPrivateAPI`; they're not relevant in this codebase
39+
- 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)
40+
- 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
41+
- 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
42+
- 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

prompt-applyOperationsScenarios.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 (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 applyOperationsScenarios to Swift.
16+
17+
## Detailed requirements for the ported tests
18+
19+
Take the following requirements into account when coming up with your plan.
20+
21+
- When translating the JS code to Swift, follow the existing patterns established by objectSyncSequenceScenarios where possible.
22+
23+
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.
24+
25+
- 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.
26+
- 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.
27+
- Handle JavaScript calls to the expectInstanceOf function as follows:
28+
- 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.
29+
- 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).
30+
- 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")`.
31+
- 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.
32+
- 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`.
33+
- 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.
34+
- 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.`
35+
- Our ObjectsHelper doesn't take a helper argument.
36+
- 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.
37+
- We have no helper instance that's passed to each test; the methods that exist on `helper` are currently just static methods on `Helper`.
38+
- do not copy the calls to `helper.recordPrivateAPI`; they're not relevant in this codebase
39+
- 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)
40+
- 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
41+
- 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
42+
- 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)