Skip to content

Commit 620b732

Browse files
authored
Merge pull request #18 from cipherstash/chore/add-linting-and-formatting
Chore: add linting and formatting
2 parents c3a0d3d + 3166da8 commit 620b732

File tree

9 files changed

+242
-40
lines changed

9 files changed

+242
-40
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- name: Build
6464
shell: bash
6565
run: npm run debug
66-
- name: Test (unit)
66+
- name: Test (typecheck, lint, & Rust)
6767
shell: bash
6868
run: npm test
6969
- name: Install integration test dependencies

README.md

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ Initiate a dry run of a patch release of this library via GitHub Actions. This p
7676

7777
#### `npm test`
7878

79-
Runs the unit tests by calling `cargo test`. You can learn more about [adding tests to your Rust code](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) from the [Rust book](https://doc.rust-lang.org/book/).
79+
Formats and lints Rust and TypeScript code.
80+
Also runs Rust tests.
81+
82+
Note: `npm test` at project root does not run integration tests.
83+
For integration tests, see [below](#integration-tests).
8084

8185
## Project Layout
8286

@@ -86,6 +90,7 @@ The directory structure of this project is:
8690
protect-ffi/
8791
├── Cargo.toml
8892
├── README.md
93+
├── integration-tests/
8994
├── lib/
9095
├── src/
9196
| ├── index.mts
@@ -99,40 +104,65 @@ protect-ffi/
99104
└── target/
100105
```
101106

102-
| Entry | Purpose |
103-
|----------------|------------------------------------------------------------------------------------------------------------------------------------------|
104-
| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. |
105-
| `README.md` | This file. |
106-
| `lib/` | The directory containing the generated output from [tsc](https://typescriptlang.org). |
107-
| `src/` | The directory containing the TypeScript source files. |
108-
| `index.mts` | Entry point for when this library is loaded via [ESM `import`](https://nodejs.org/api/esm.html#modules-ecmascript-modules) syntax. |
109-
| `index.cts` | Entry point for when this library is loaded via [CJS `require`](https://nodejs.org/api/modules.html#requireid). |
110-
| `crates/` | The directory tree containing the Rust source code for the project. |
111-
| `lib.rs` | Entry point for the Rust source code. |
112-
| `platforms/` | The directory containing distributions of the binary addon backend for each platform supported by this library. |
113-
| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. |
114-
| `target/` | Binary artifacts generated by the Rust build. |
107+
| Entry | Purpose |
108+
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
109+
| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. |
110+
| `README.md` | This file. |
111+
| `integration-tests/` | The directory containing integration tests. |
112+
| `lib/` | The directory containing the generated output from [tsc](https://typescriptlang.org). |
113+
| `src/` | The directory containing the TypeScript source files. |
114+
| `index.mts` | Entry point for when this library is loaded via [ESM `import`](https://nodejs.org/api/esm.html#modules-ecmascript-modules) syntax. |
115+
| `index.cts` | Entry point for when this library is loaded via [CJS `require`](https://nodejs.org/api/modules.html#requireid). |
116+
| `crates/` | The directory tree containing the Rust source code for the project. |
117+
| `lib.rs` | Entry point for the Rust source code. |
118+
| `platforms/` | The directory containing distributions of the binary addon backend for each platform supported by this library. |
119+
| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. |
120+
| `target/` | Binary artifacts generated by the Rust build. |
121+
122+
## Integration tests
123+
124+
Integration tests live in the `./integration-tests` directory.
125+
These tests use the local build of Rust and JavaScript artifacts to test `@cipherstash/protect-ffi` as API consumers would.
126+
127+
These tests rely on CipherStash to be configured (via `.toml` config or environment variables).
128+
129+
Example environment variables to set:
130+
```
131+
CS_CLIENT_ID=
132+
CS_CLIENT_KEY=
133+
CS_CLIENT_ACCESS_KEY=
134+
CS_WORKSPACE_ID=
135+
```
136+
137+
To run integration tests:
138+
```
139+
npm run debug
140+
cd integration-tests
141+
npm run test
142+
```
115143

116144
## Releasing
117145

118146
Releases are handled by GitHub Actions using a `workflow_dispatch` event trigger.
119147
The [release workflow](./.github/workflows/release.yml) was generated by [Neon](https://neon-rs.dev/).
120148

121149
The release workflow is responsible for:
150+
122151
- Building and publishing the main `@cipherstash/protect-ffi` package as well as the native packages for each platform (e.g. `@cipherstash/protect-ffi-darwin-arm64`).
123152
- Creating the GitHub release.
124153
- Creating a Git tag for the version.
125154

126155
To perform a release:
156+
127157
1. Navigate to the ["Release" workflow page](https://github.com/cipherstash/protect-ffi/actions/workflows/release.yml) in GitHub.
128158
1. Click on "Run workflow".
129159
1. Select the branch to release from.
130-
Use the default of "main" unless you want to do a pre-release version or dry run from a branch.
160+
Use the default of `main` unless you want to do a pre-release version or dry run from a branch.
131161
1. Select whether or not to do a dry run.
132-
Dry runs are useful for verifying that the build will succeed for all platforms before doing a full run with a publish.
162+
Dry runs are useful for verifying that the build will succeed for all platforms before doing a full run with a publish.
133163
1. Choose a version to publish.
134-
The options are similar to [`npm version`](https://docs.npmjs.com/cli/v11/commands/npm-version).
135-
Select "custom" in the dropdown and fill in the "Custom version" text box if you want to use a semver string instead of the shorthand (patch, minor, major, etc.).
164+
The options are similar to [`npm version`](https://docs.npmjs.com/cli/v11/commands/npm-version).
165+
Select "custom" in the dropdown and fill in the "Custom version" text box if you want to use a semver string instead of the shorthand (patch, minor, major, etc.).
136166
1. Click "Run workflow".
137167

138168
Note that we currently don't have any automation around release notes or a changelog.

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
33
"files": {
4-
"ignore": ["**/package.json", ".turbo/", "dist"]
4+
"ignore": ["**/package.json", ".turbo/", "lib", "target"]
55
},
66
"formatter": {
77
"indentStyle": "space",

crates/protect-ffi/src/encrypt_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl FromStr for EncryptConfig {
158158
}
159159

160160
impl EncryptConfig {
161-
pub fn to_config_map(self) -> HashMap<Identifier, ColumnConfig> {
161+
pub fn into_config_map(self) -> HashMap<Identifier, ColumnConfig> {
162162
let mut map = HashMap::new();
163163
for (table_name, columns) in self.tables.into_iter() {
164164
for (column_name, column) in columns.into_iter() {
@@ -211,7 +211,7 @@ mod tests {
211211

212212
fn parse(json: serde_json::Value) -> HashMap<Identifier, ColumnConfig> {
213213
serde_json::from_value::<EncryptConfig>(json)
214-
.map(|config| config.to_config_map())
214+
.map(|config| config.into_config_map())
215215
.unwrap()
216216
}
217217

crates/protect-ffi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async fn new_client_inner(encrypt_config: EncryptConfig) -> Result<Client, Error
133133
Ok(Client {
134134
cipher: Arc::new(cipher),
135135
zerokms,
136-
encrypt_config: Arc::new(encrypt_config.to_config_map()),
136+
encrypt_config: Arc::new(encrypt_config.into_config_map()),
137137
})
138138
}
139139

integration-tests/tests/index.test.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { expect, test } from "vitest";
1+
import { expect, test } from 'vitest'
22

3-
import { newClient, encrypt, decrypt } from "@cipherstash/protect-ffi"
3+
import { decrypt, encrypt, newClient } from '@cipherstash/protect-ffi'
44

5-
test("can round-trip encrypt and decrypt", async () => {
5+
test('can round-trip encrypt and decrypt', async () => {
66
const encryptConfig = {
77
v: 1,
88
tables: {
@@ -16,15 +16,13 @@ test("can round-trip encrypt and decrypt", async () => {
1616
},
1717
},
1818
},
19-
};
19+
}
2020

21-
const client = await newClient(
22-
JSON.stringify(encryptConfig)
23-
);
21+
const client = await newClient(JSON.stringify(encryptConfig))
2422

25-
const ciphertext = await encrypt(client, "abc", "email", "users");
23+
const ciphertext = await encrypt(client, 'abc', 'email', 'users')
2624

27-
const plaintext = await decrypt(client, JSON.parse(ciphertext).c);
25+
const plaintext = await decrypt(client, JSON.parse(ciphertext).c)
2826

29-
expect(plaintext).toBe("abc");
30-
});
27+
expect(plaintext).toBe('abc')
28+
})

integration-tests/tsconfig.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"noEmit": true,
5-
},
6-
"include": ["tests/**/*.ts"],
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true
5+
},
6+
"include": ["tests/**/*.ts"]
77
}

package-lock.json

Lines changed: 165 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
"description": "",
55
"main": "./lib/index.cjs",
66
"scripts": {
7-
"test": "tsc &&cargo test",
7+
"test": "npm run test:typecheck && npm run test:lint && npm run test:format && npm run test:rust",
8+
"test:typecheck": "tsc",
9+
"test:rust": "cargo test",
10+
"test:lint": "npm run test:lint:rust && npm run test:lint:ts",
11+
"test:lint:ts": "biome lint",
12+
"test:lint:rust": "cargo clippy --all --no-deps --all-targets --all-features -- -D warnings",
13+
"test:format": "npm run test:format:rust && npm run test:format:ts",
14+
"test:format:ts": "biome format",
15+
"test:format:rust": "cargo fmt --check",
816
"cargo-build": "tsc &&cargo build --message-format=json-render-diagnostics > cargo.log",
917
"cross-build": "tsc &&cross build --message-format=json-render-diagnostics > cross.log",
1018
"postcargo-build": "neon dist < cargo.log",
@@ -43,6 +51,7 @@
4351
"prefix": "protect-ffi-"
4452
},
4553
"devDependencies": {
54+
"@biomejs/biome": "1.9.4",
4655
"@neon-rs/cli": "^0.1.82",
4756
"@tsconfig/node20": "^20.1.4",
4857
"@types/node": "^20.11.16",

0 commit comments

Comments
 (0)