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
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
branches: ['main', main*]
pull_request:
# The branches below must be a subset of the branches above
branches: ['main']
branches: ['main', 'main*']
schedule:
- cron: '0 2 * * 6'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/live-share-build-samples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build Live Share SDK samples

on:
push:
branches: [ main ]
branches: [ main, mainv2 ]
pull_request:
branches: [ main ]
branches: [ main, mainv2 ]

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/live-share-test-packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Test Live Share SDK packages

on:
push:
branches: [ main ]
branches: [ main, mainv2 ]
pull_request:
branches: [ main ]
branches: [ main, mainv2 ]

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -365,5 +365,6 @@ docs/assets/main.js

# Testing files
coverage/
nyc/
.nyc_output/
build-data.json
52 changes: 52 additions & 0 deletions internal/test-utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Compiled TypeScript and CSS
dist
lib

# Babel
public/scripts/es5

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
.cache-loader

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Typings
typings

# Debug log from npm
npm-debug.log

# Code coverage
nyc
.nyc_output/

# Chart dependencies
**/charts/*.tgz

# Generated modules
intel_modules/
temp_modules/
6 changes: 6 additions & 0 deletions internal/test-utils/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
nyc
*.log
**/*.tsbuildinfo
src/test
dist/test
**/_api-extractor-temp/**
21 changes: 21 additions & 0 deletions internal/test-utils/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation and contributors. All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions internal/test-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This package contains code to setup tests for live share data objects using a local fluid server.

Code is duplicated and simplified from "@fluid-private/test-version-utils" and "@fluid-private/test-drivers", which are no longer available over npm in fluid v2.
62 changes: 62 additions & 0 deletions internal/test-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "@live-share-private/test-utils",
"version": "2.0.0-internal.2",
"description": "testing utils for live share",
"repository": {
"type": "git",
"url": "https://github.com/microsoft/live-share-sdk",
"directory": "internal/test-utils"
},
"license": "MIT",
"author": "Microsoft and contributors",
"sideEffects": false,
"main": "./bin/index.js",
"types": "./bin/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.json",
"eslint": "eslint --format stylish src",
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
"format": "npm run prettier:fix",
"lint": "npm run prettier && npm run check:release-tags && npm run eslint",
"lint:fix": "npm run prettier:fix && npm run eslint:fix",
"prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
"prettier:fix": "prettier --write . --cache --ignore-path ../../../.prettierignore",
"tsc": "tsc"
},
"dependencies": {
"@fluid-experimental/attributor": "^2.0.0-rc.1",
"@fluid-experimental/sequence-deprecated": "^2.0.0-rc.1",
"@fluidframework/agent-scheduler": "^2.0.0-rc.1",
"@fluidframework/aqueduct": "^2.0.0-rc.1.0.3",
"@fluidframework/cell": "^2.0.0-rc.1",
"@fluidframework/container-loader": "^2.0.0-rc.1.0.3",
"@fluidframework/container-runtime": "^2.0.0-rc.1.0.4",
"@fluidframework/core-interfaces": "^2.0.0-rc.1",
"@fluidframework/core-utils": "^2.0.0-rc.1",
"@fluidframework/counter": "^2.0.0-rc.1",
"@fluidframework/datastore-definitions": "^2.0.0-rc.1.0.4",
"@fluidframework/driver-definitions": "^2.0.0-rc.1",
"@fluidframework/local-driver": "^2.0.0-rc.1",
"@fluidframework/map": "^2.0.0-rc.1.0.4",
"@fluidframework/matrix": "^2.0.0-rc.1",
"@fluidframework/ordered-collection": "^2.0.0-rc.1",
"@fluidframework/register-collection": "^2.0.0-rc.1.0.4",
"@fluidframework/runtime-definitions": "^2.0.0-rc.1.0.4",
"@fluidframework/sequence": "^2.0.0-rc.1.0.4",
"@fluidframework/server-local-server": "^3.1.0-237980",
"@fluidframework/telemetry-utils": "^2.0.0-rc.1.0.4",
"@fluidframework/test-driver-definitions": "^2.0.0-rc.1",
"@fluidframework/test-utils": "^2.0.0-rc.1.0.3"
},
"devDependencies": {
"@fluidframework/eslint-config-fluid": "^3.5.0",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"eslint": "~8.56.0",
"eslint-plugin-unused-imports": "^3.1.0",
"mocha-json-output-reporter": "^2.0.1",
"mocha-multi-reporters": "^1.5.1",
"prettier": "~3.0.3",
"rimraf": "^4.4.0",
"typescript": "~5.1.6"
}
}
148 changes: 148 additions & 0 deletions internal/test-utils/src/compatUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

import { IFluidLoadable } from "@fluidframework/core-interfaces";
import {
IFluidDataStoreContext,
IFluidDataStoreFactory,
} from "@fluidframework/runtime-definitions";
import {
IFluidDataStoreRuntime,
IChannelFactory,
} from "@fluidframework/datastore-definitions";
import { ISharedDirectory } from "@fluidframework/map";
import { unreachableCase } from "@fluidframework/core-utils";
import {
ITestContainerConfig,
DataObjectFactoryType,
ChannelFactoryRegistry,
createTestContainerRuntimeFactory,
TestObjectProvider,
} from "@fluidframework/test-utils";
import { mixinAttributor } from "@fluid-experimental/attributor";
import { ContainerRuntimeApi, DataRuntimeApi, LoaderApi } from "./testApi";
import { LocalServerTestDriver } from "./localServerTestDriver";
import { LocalDriverApi } from "./localDriverApi";

/**
* @internal
*/
export const TestDataObjectType = "@fluid-example/test-dataStore";

/**
* @internal
*/
export interface ITestDataObject extends IFluidLoadable {
_context: IFluidDataStoreContext;
_runtime: IFluidDataStoreRuntime;
_root: ISharedDirectory;
}

function createGetDataStoreFactoryFunction(api: typeof DataRuntimeApi) {
class TestDataObject extends api.DataObject implements ITestDataObject {
public get _context() {
return this.context;
}
public get _runtime() {
return this.runtime;
}
public get _root() {
return this.root;
}
}

const registryMapping: { [index: string]: any } = {};
for (const value of Object.values(api.dds)) {
registryMapping[value.getFactory().type] = value.getFactory();
}

function convertRegistry(
registry: ChannelFactoryRegistry = []
): ChannelFactoryRegistry {
const oldRegistry: [string | undefined, IChannelFactory][] = [];
for (const [key, factory] of registry) {
const oldFactory = registryMapping[factory.type];
if (oldFactory === undefined) {
throw Error(
`Invalid or unimplemented channel factory: ${factory.type}`
);
}
oldRegistry.push([key, oldFactory]);
}

return oldRegistry;
}

return function (
containerOptions?: ITestContainerConfig
): IFluidDataStoreFactory {
const registry = convertRegistry(containerOptions?.registry);
const fluidDataObjectType = containerOptions?.fluidDataObjectType;
switch (fluidDataObjectType) {
case undefined:
case DataObjectFactoryType.Primed:
return new api.DataObjectFactory(
TestDataObjectType,
TestDataObject,
[...registry].map((r) => r[1]),
{}
);
case DataObjectFactoryType.Test:
return new api.TestFluidObjectFactory(registry);
default:
unreachableCase(
fluidDataObjectType,
`Unknown data store factory type ${fluidDataObjectType}`
);
}
};
}

// Only support current version, not baseVersion support
/**
* @internal
*/
export const getDataStoreFactory =
createGetDataStoreFactoryFunction(DataRuntimeApi);

/**
* @internal
*/
export async function getVersionedTestObjectProviderFromApis(
apis: Omit<CompatApis, "dds">
) {
const driver = new LocalServerTestDriver(LocalDriverApi);

const getDataStoreFactoryFn = createGetDataStoreFactoryFunction(
apis.dataRuntime
);
const containerFactoryFn = (containerOptions?: ITestContainerConfig) => {
const dataStoreFactory = getDataStoreFactoryFn(containerOptions);
const runtimeCtor =
containerOptions?.enableAttribution === true
? mixinAttributor(apis.containerRuntime.ContainerRuntime)
: apis.containerRuntime.ContainerRuntime;
const factoryCtor = createTestContainerRuntimeFactory(runtimeCtor);
return new factoryCtor(
TestDataObjectType,
dataStoreFactory,
containerOptions?.runtimeOptions
);
};

return new TestObjectProvider(
apis.loader.Loader,
driver,
containerFactoryFn
);
}

export interface CompatApis {
containerRuntime: typeof ContainerRuntimeApi;
dataRuntime: typeof DataRuntimeApi;
dds: (typeof DataRuntimeApi)["dds"];
driver: typeof LocalDriverApi;
loader: typeof LoaderApi;
}
Loading